nohup sh xxx.sh &>/dev/null &

nohup sh xxx.sh &> / dev / null & or other similar wording nohup ./xxx [args] &> / dev / null &

The role of the command is: xxx processes running in the background and standard output and standard error streams redirected to the null device linux

For each section the following command, illustrate (a part of a different color):

nohup sh xxx.sh &>/dev/null &

nohup : is no hangup, do not hang up, ignore hup signal. Output to standard output the contents of the log file in the current directory nohup.out without terminal display.

Figuratively, you start a process in the terminal xxx.sh, running in the background, and then close the current terminal (in the foreground, close the terminal will certainly have to terminate the process). Close the current terminal, the current terminal start (background) process will quit. If you want to close the terminal, but the process does not terminate, continue to run in the background, it would have to use the nohup.

nohup not ctrl + z, ctrl + z is the current process to hang.

I will explain the way down ctrl + z, younger talent and less learning, under normal use of his or her own experience used to share, that's the wrong place also please feel free to correct me. ctrl + z will make the current process running the foreground to the background hangs, then the process stops running, you can see these tasks using jobs, by fg, bg allow these processes to continue running in the foreground or the background. But the current terminal is closed, these processes also will withdraw.

sh xxx.sh is executing the script xxx.sh, behind ./main [args] also similar meaning, started a process, followed by the relevant parameters

So nohup sh xxx.sh mean xxx.sh use the nohup command to execute the script, but only if this is the case is just the foreground, but this time, the original script xxx.sh through the standard output stream should output the contents of the screen, then the output nohup.out to a document which, even in the foreground, foreground do not see what the information.

&> : And and & redirection symbol (>) put together that no spaces. linux file number, the standard output stream 1, stream 2 is the error output, the meaning herein &> and the combined error output and standard output redirection, and & remember> no spaces, spaces, then becomes & It is running in the background mean. Therefore, usually using 1> or 2> are similar meaning, where to redirect the standard output stream or streams where to redirect the error output.

/ dev / null: see / dev to understand that this is in the linux directory of the device. / dev / null linux is an empty device, placed where the data immediately clear, we can only write what could not be read. Can understand / dev / null, as if he were invisible, filled up the abyss, what were here, there is no throw.

Therefore, &> / dev / null mean, the standard output and standard error stream redirected to / dev / null, of course, can be redirected to another file. For example: 1> run.log 2> error.log, written to standard output stream run.log, error output stream written erro.log. Redirected to / dev / null because the content I do not care, so I do not need it falls somewhere in space, because the front using the nohup command, where if you do not specify a redirect to, the default is to be appended to the nohup.out file.

Some people may wonder what the log content is not concerned directly discarded, an analogy, some logs both will fall into a local terminal will output to the screen, but I just need to fall into local log enough, this time, It can be so used.

The last & : & is the meaning of this last surface running in the background.

In this case, this is not a command has been somewhat clear understanding, can also be needed, flexible use.

Published 136 original articles · won praise 81 · views 180 000 +

Guess you like

Origin blog.csdn.net/x763795151/article/details/99695096