nohup command: If you are running a process and you think that the process will not end when you log out of your account, you can use the nohup command. This command can continue running the corresponding process after you log out of the account/close the terminal. nohup means don't hang up. The general form of this command is: nohup command & ls xxx 1>out.txt 2>&1 nohup /mnt/Nand3/H2000G >/dev/null 2>&1 & & 1 is more accurately file descriptor 1, which generally refers to STDOUT_FILENO. This operation is actually a dup2(2) call. It outputs the standard output to all_result, and then copies the standard output to file descriptor 2 (STDERR_FILENO). As a result, file descriptors 1 and 2 point to the same file table entry, or the error output is merged. 0 represents keyboard input, 1 represents screen output, and 2 represents error output. The standard error is redirected to the standard output and then thrown into /DEV/NULL. In layman's terms, it means throwing all standard output and standard errors into the trash can. command >out.file 2>&1 & command >out.file redirects the output of command to the out.file file, that is, the output content is not printed on the screen, but output to the out.file file. 2>&1 redirects the standard error to the standard output. The standard output here has been redirected to the out.file file, that is, the standard error is also output to the out.file file. The last & causes the command to be executed in the background. Think about what 2>1 means, 2 combined with > means error redirection, and 1 means that errors are redirected to a file 1, not to standard output; You can use Why should 2>&1 be written at the end? command > file 2>&1 First, command > file redirects the standard output to file, and 2>&1 is the standard error copying the standard output, that is, it is also redirected to file. The final result is that both the standard output and the error are redirected to file. command 2>&1 >file 2>&1 Standard error copies the behavior of standard output, but standard output is still in the terminal. >file The output is redirected to file, but the standard error remains in the terminal. Using strace you can see: 1. command > file 2>&1 open(file) == 3 dup2(3,1) dup2(1,2) 2. command 2>&1 >file dup2(1,2) open(file) == 3 dup2(3,1) Why do we use /dev/null 2>&1? This command means redirecting all standard output and error output to /dev/null, that is, discarding all generated information. Let me tell you the difference between command > file 2>file and command > file 2>&1. First of all, command > file 2>file means to send the standard output information and error output information generated by the command to file. In this way, stdout and stderr are directly sent to file, and file will be opened twice, so stdout and stderr will overwrite each other. This is equivalent to using FD1 and FD2 to simultaneously occupy the pipe of file. The command >file 2>&1 sends stdout directly to file, and stderr inherits the FD1 pipe and is then sent to file. At this time, file is only opened once, and only one pipe FD1 is used, which includes the contents of stdout and stderr. From the perspective of IO efficiency, the efficiency of the first command is lower than that of the second command, so when writing shell scripts, we often use command > file 2>&1. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Comparing the performance of int, char, and varchar in MySQL
>>: Analysis and solution of MySQL connection throwing Authentication Failed error
I have recently studied the hollowing effect. bac...
The specific method of installing CentOS 7.0 on V...
Flex layout is a commonly used layout method nowa...
I recently bought the cheapest Tencent cloud serv...
1. Introduction to Docker Docker is developed in ...
Table of contents Introduction to Anaconda 1. Dow...
Preface When scroll events such as scroll and res...
What if the basic images have been configured bef...
Preface Nowadays, in projects, the Axios library ...
Table of contents Effects Documentation first ste...
Preface The electricity in my residence has been ...
1. Install the express library and generator Open...
Dig Introduction: Dig is a tool that queries DNS ...
This article example shares the specific code of ...
Table of contents Introduction Install Display Fi...