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:
Alternatively, if the command is already running (ie in the background), it can be allowed to continue by using disown before closing the shell:
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:
Code:
nohup command
Code:
disown -h process-id
Total Comments 2
Comments
-
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 -
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".
Code:$ 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 ^C $ 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 ^C $
Posted 11-08-2011 at 10:35 PM by rocket357
Updated 11-08-2011 at 10:42 PM by rocket357