Detaching a running process from a bash shell

When I run a command on a machine that I am ssh’ed into, most of the time I want to kill the connection but have the command continue to execute.

There are several ways to detach a process from the current shell:

The first is to start the process with:

nohup command &

However, I usually start a command and forget to detach it initially. An easy way to detach a currently running process from a shell is like this:

disown %1

These methods daemonise a running process and make the process ignore the SIGHUP command so that when you close you shell or ssh connection, the command continues to run. For more information check out the man pages for disown and nohup.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s