LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Blogs > neonsignal
User Name
Password

Notices

Rate this Entry

allowing commands to continue after parent shell exit

Posted 11-05-2011 at 06: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:
Code:
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:
Code:
disown -h process-id
Posted in Uncategorized
Views 7297 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  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 10: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".

    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 11:35 PM by rocket357 rocket357 is offline
    Updated 11-08-2011 at 11:42 PM by rocket357
 

  



All times are GMT -5. The time now is 03:18 PM.

Main Menu
Advertisement

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