Tuesday, October 16, 2012

Run job in background and not terminated after logout in Linux

ISSUE:
We'd like to run a job in background and not terminated after logout after we already start the job or forget to use nohup or forget to include & at  the end.

SOLUTION:
we can use below command from shell prompt to fix the issue.
Cntl Z + bg
jobs
nohup
disown
disown -h   (will keep the process to current shell's process tree until you exit.)

e.g.
1. start a job and run foregroud
a. Crtl Z  -- stop the job to get back to shell prompt
b. jobs  -- list jobs with job_id
c. bg job_id -- start the job in backgroud
d. disown -h %job_id
2. start a job with nohup but forget to include & at the end
a. Crtl Z -- stop the job to get back to shell prompt
b. jobs -- list jobs with job_id
c. bg job_id --start the job in background
3. start a job without nohup in background
a. jobs -- list jobs with job_id
b. disown -h %job_id


reference:
http://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and
http://linux-quirks.blogspot.com/2011/04/nohup-or-disown.html
http://www.quantprinciple.com/invest/index.php/docs/tipsandtricks/unix/jobcontrol/
http://stackoverflow.com/questions/625409/how-do-i-put-an-already-running-process-under-nohup

No comments:

Post a Comment