Detach a running process – Linux

Pub.

Sometimes I start a job remotely and only after I remember that I may need to log-off, but the process must continue to run afterwards. This can be done with command disown. On the same shell where your process is running type Ctrl+Z, to pause the program, you’ll see the job id, something like [1], you need it for the disown command, now restart the job in background with the command bg and you’re ready to issue the disown command:

disown -h %1

you can also use the pid1 of the process (use jobs -l on that same shell and you’ll get a longer number that is the pid of the process you want to detach):

disown -h pid

after that you can close the shell with exit or Ctrl+D.

If you start your program with nohup2 or screen you don’t have to worry about log-off and running processes.

This command can also be used in Unix (such as BSD/MacOS X/etc.) but their might be implementation differences.

1 After some interaction on Google+ with CNF we found out that the pid is accepted but it is not documented. I’ve changed the post to reflect a more appropriated use of the disown command (according to the manual).

2 disown -h is is basically a nohup a posteriori.

Solution found on serverFault.

facebooktwittergoogle_plusredditpinterestlinkedinmail
Posted in Linux. Tags: , . 2 Comments »

Pub.

2 Responses to “Detach a running process – Linux”

  1. neil diz:
    (Mozilla Firefox 16.0 Ubuntu Linux)
    Mozilla Firefox 16.0 Ubuntu Linux

    how do you “re-own?”

  2. Bruno Lucas diz:
    (Debian IceWeasel 17.0 Linux)
    Debian IceWeasel 17.0 Linux

    Good question 🙂
    Maybe with reptyr, found it here.

Leave a Reply

Pub.