Help answer threads with 0 replies.
Go Back > Blogs > neonsignal
User Name


Rate this Entry

allowing commands to continue after parent shell exit

Posted 11-05-2011 at 05:52 AM by neonsignal

Because commands that are started from a shell are child processes, they will normally be terminated when the shell exits.

A command can be run with nohup so that it can continue beyond the life of the parent shell, and output will be directed to the file nohup.out:
nohup command
Alternatively, if the command is already running (ie in the background), it can be allowed to continue by using disown before closing the shell:
disown -h process-id
Posted in Uncategorized
Views 11613 Comments 2
« Prev     Main     Next »
Total Comments 2


  1. Old Comment
    GNU screen is also useful if you want to exit and resume later, e.g. over ssh.
    Posted 11-05-2011 at 09:49 AM by ewqdsacxz ewqdsacxz is offline
  2. Old Comment
    Alternatively, you can put "&" after the command before closing the shell, which daemonizes the child process. If the child process is already running, you can temporarily suspend it by hitting Ctrl-Z, then typing in "bg" (which "continues" the process daemonized). To bring the process back to the foreground, run "fg".

    $ sleep 100 # this is the process we'll daemonize
    ^Z # Ctrl-Z is immediate, Ctrl-Y suspends the process when it tries to read input
    [1]+  Stopped                 sleep 100
    $ bg # short for "background"...only works on suspended processes
    [1]+ sleep 100 &  <~~~ same as if you'd run "sleep 100 &" from the start
    $ time sleep 5 # a different "sleep" process
    real	0m5.003s
    user	0m0.004s
    sys	0m0.000s
    $ fg # bring the "old" sleep process that we daemonized back to the foreground
    sleep 100
    $ sleep 200 & # daemonize the process from the start
    [1] 2117
    $ ps aux | grep sleep # look at the daemonized process
    user      2117  0.0  0.0   3232   616 pts/1    S    22:33   0:00 sleep 200
    $ fg # bring the daemonized process back to the foreground
    sleep 200
    Posted 11-08-2011 at 10:35 PM by rocket357 rocket357 is offline
    Updated 11-08-2011 at 10:42 PM by rocket357


All times are GMT -5. The time now is 02:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration