3

I ssh into a server than start a job (for instance rsync), then I just want to be able to log out from the server and let the job run its course. But if I just do rsync ... & I think it's still connected to the tty in some way, and that the job dies when the tty goes away when logging out. Is there any (easy) way to disconnect the process from the tty to be able to log out without the process terminating?

7

you could start it in a screen

  • +1 to using screen. – gravyface Mar 24 '10 at 12:49
  • +1 also to using screen. It's simply to use and once you get used to it, you'll never want to be without it. I would consider it one the most valuable tools I use in the Unix world. – MT. Mar 24 '10 at 12:52
  • Thanks but n00b as I am I don't know how. Example cmdline might be helpful. – Jonas Byström May 3 '10 at 10:10
4
nohup rsync ... &

Seems to do exactly what I want.

1

Use setsid and redirect handles 1 and 2 to /dev/null.

e.g.

setsid \
  perl -e 'for ( my $i = 0; 1; $i++ ) { $0 = "forever $i"; sleep( 1 ); }' \
  1>/dev/null \
  2>/dev/null

Without setsid and a trailing ampersand the command ps ax shows:

13526 pts/4    S      0:00 forever 11

With setsid and no trailing ampersand the command ps ax shows:

13520 ?        Ss     0:00 forever 68

...indicating no attached TTY.

1

In Linux (Ubuntu at least) you can use start-stop-daemon

If all you want is to start a process and leave it running, you can use

at now
0

Debian and Ubuntu have a package called daemon which seems to be part of the libslack project.

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.