How do I keep jobs running after logout?

4

1

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

Posted 2010-09-20T20:47:05.803

Reputation: 1 974

Question was closed 2011-04-27T19:04:47.727

Answers

2

I think another alternative would be to use screen.

vtest

Posted 2010-09-20T20:47:05.803

Reputation: 4 424

nohup is one option, but screen is a much better solution. +1. – peelman – 2010-09-21T02:01:33.697

1How should i run my script using screen? – David B – 2010-09-21T09:56:14.597

3

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

Posted 2010-09-20T20:47:05.803

Reputation: 27 121

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

Posted 2010-09-20T20:47:05.803

Reputation: 121

1

You can use nohup

nohup /path/to/script.pl &

cafe101

Posted 2010-09-20T20:47:05.803

Reputation: 11