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?

Jonas Byström
  • 194
  • 2
  • 12

5 Answers5

7

you could start it in a screen

tliff
  • 145
  • 1
  • 1
  • 9
  • +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 03 '10 at 10:10
3
nohup rsync ... &

Seems to do exactly what I want.

Jonas Byström
  • 194
  • 2
  • 12
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.

PP.
  • 3,316
  • 6
  • 27
  • 31
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
Dan Andreatta
  • 5,454
  • 2
  • 24
  • 14
0

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

ptman
  • 28,394
  • 2
  • 30
  • 45