I know you can use nohup to keep a job running after logging out, but what about a process that's already running?

Is there a way to change it's state, so that it continues to run even when I log out?


In Bash, you could disown the process.

disown [-ar] [-h] [jobspec … ]     

Each jobspec is removed from the table of active jobs.

  • -h SIGHUP is not sent to the job if the shell receives a SIGHUP. current job .
  • -a all the -r running jobs.

See also: Shell stuff: job control and screen

If you use the bash shell, then you have an alternative (don't you always?) Instead of using nohup, just run the command normally, put it in the background one of the two ways we've discussed, and then disown -h the job.

$ tar cjf /backup/rob/home.tar.bz2 . &

[1] 32089
$ disown -h

You can then safely logout or close your terminal. As with nohup, if you close the terminal or logout, you will not be able to access that command directly using the jobs and %<N> or fg <N> commands..

Related posts on the Stack Exchange network:

| improve this answer | |
  • The Z shell also has % substitution - eg your example could be typed as disown %[TAB] and zsh would expand it to disown %tar. Out of curiosity - does bash have a similar mechanism? – new123456 Nov 3 '11 at 0:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.