D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] ssh and programs (not) continuing to run

 

On Tue, 26 Apr 2011, Martijn Grooten wrote:

Not so much a question, as wondering whether what I observed
empirically somehow makes sense.

When I ssh into a remote server and run a program and then the
connection is terminated (because of a connection issue, or because
ssh is killed), the program dies too. Even if it was running in the
background.

However, when I do the same but manually exit the ssh connection after
making the program run in the background, the program continues to
run.

So:
ssh me@remote
foo.sh &
[connection dies]
[foo.sh dies too]

But
ssh me@remote
foo.sh &
exit
[foo.sh is still running]

Does this make sense?

Yes.

But I guess you want to know why ... When the connection is terminated abnormally, a "hangup" signal is sent to the child processes. Think of the olden days with modems...

You can get round this with the nohup command.

e.g.

  nohup foo.sh &

but do read the man page as nohup fiddles with stdin & stdout...

Gordon

--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq