6

Possible Duplicate:
How do I fork a process that doesn't die when shell exits?

Sometimes I remotely connect to my Ubuntu using NX. I then run some jobs in the background, e.g.:

$ /path/to/script.pl &

However, when I log out, the jobs stop running.

How can I make them continue even after I log out?

David B
  • 2,614

4 Answers4

4

The shell kills all processes in its process group when it ends, by sending SIGHUP.

If you run the bash shell, you can type disown to keep it running after you log out. This removes it from the list of processes it will send signals to.

Or you can launch the script with nohup, but then you have to remember this when you run the command. This tells your command to ignore the SIGHUP signal that the shell will send. This will work on any shell.

Rich Homolka
  • 32,350
2

I think another alternative would be to use screen.

vtest
  • 5,358
2

You can use nohup

nohup /path/to/script.pl &
cafe101
  • 21
2

See "Keep linux scripts running after you have closed a remote shell" for how to do this using the screen command.

The answer lies in a command line tool called screen.

Screen allows you to start a process on a virtual screen, then detach that screen and do >something else (including log out). You can also reattach your screen after logging out >and logging in again.

If you dont have the screen command on your remote linux box, first install it either from source or using your favourite package manager. Then login into your remote box and run your desired command prefixed with “screen”. For example:

screen top

Now to detach the screen use CTRL+a followed by d. This will detach your screen and you can go about any other business, including quitting your remote session.

Reattaching you screen at any time is as simple as running the command:

screen -r

chrowe
  • 121