linux command of nohub

back to the top

nohup

nohup runs a command specified by the Command parameter and any related Arg parameters of command, ignore all hang (SIGHUP) signals. The program runs in the background using nohup command after logout. To run a background in nohup command, add & (representation "and" sign) to the end of the command.

nohup is no hang up the acronym, just do not hang up the meaning.

nohup command: If you are running a process, and you feel that the process will not end when you exit your account, you can use the nohup command. The command to exit your account / continue to run the process after closing the corresponding terminal.

All default output the job is redirected to a file named in nohup.out.

Case

1. nohup command > myout.file 2>&1 &   

In the above example, 0 - stdin (standard input), 1 - stdout (standard output), 2 - stderr (standard error);
2> & 1 is the standard error (2) is redirected to the standard output (& 1), the standard output (& 1) and then is inputted to the redirected myout.file file.

2. 0 22 * * * /usr/bin/python /home/pu/download_pdf/download_dfcf_pdf_to_oss.py > /home/pu/download_pdf/download_dfcf_pdf_to_oss.log 2>&1

This is a timed task on the crontab, 22 o'clock at night, when fear this task, start the python script and the log file written download_dfcf_pdf_to_oss.log

nohup and & differences

&: Refers to run in the background

nohup: do not hang up the run, and did not pay attention to the function running in the background ,, refers to, with the nohup command to run the command permanent execution continues, and the user terminal does not matter, for example, we disconnect the SSH connection will not affect his run, do not pay attention to the meaning nohup running in the background; & is running in the background


 

& Means run in the background, but when users launch (hang) when the command automatically also pulled out

So, we can skillfully combine their use of it is
nohup COMMAND &
this can make the order permanent in the background
E.g:

1. sh test.sh &  
the sh test.sh tasks in the background, even if you close xshell exit the current session still continue to run, but the standard output and standard error information is lost (missing output log)

The sh test.sh tasks in the background, close xshell, along with the corresponding task to stop.
2. nohup sh test.sh  
the sh test.sh task in the background, close the standard input, the terminal can no longer receive any input (standard input) , redirect the standard output and standard error file in the current directory nohup.out, even if you close xshell exit the current session still continue to run.
3. nohup sh test.sh & 
the sh test.sh task into the background, but you can still use the standard input, the terminal is capable of receiving any input , standard output and standard error redirected to file in the current directory nohup.out, even if you close xshell exit the current session still continue to run.

Guess you like

Origin www.cnblogs.com/meizhoulqp/p/12519608.html