http://www.technicalpage.net/search/label/SQL

>> nohup command UNIX


nohup(No Hangup)

While running a background job, if we log out of the terminal/computer or lose power , the execution is lost.  If you want the job/code to continue executing in the background even though you log out or lose power,  you use the word "nohup " in the beginning of the code.

nohup  sleep 1000 &
nohup  sh unixJob  1>file1  2>file2  & 
As soon as you click ENTER to run the code/job , you get below information :

[1]   4923 
nohup: appending output to `nohup.out'

where :
[1] is job number and 4923  is the PID.
And if we do not mention the file for directing the output , unix itself creates a file , nohup.out, and redirects the output to that file.

The second line , for redirecting the output to nohup.out,  will not be displayed in below runs because we are already providing the file to redirect the output:
nohup  sleep 10  1>result.txt   2>&1 &
nohup  sleep 10  1>result.txt   &

Job Status when "nohup" is used:

Run jobs in the background and to know the status ENTER "jobs"
[1]+  Done             nohup sleep 10 --- DONE
[1]-  Running         nohup sleep 500 & --- in QUEUE
[2]+  Running        nohup sleep 50 & --- RUNNING

If you do not use "&" at the end , the job will run in the foreground and occupies your terminal until the job completes.


No comments:

Post a Comment