0

When using SSH to send a command to a remote server, if the SSH connection dies the process keeps running. Are there any ways to have it kill the child processes if the SSH connection ends?

Example:

root@local:~# ssh root@server sleep 100 &
[2] 15762

root@local:~# kill 15762
[2]+  Stopped                 ssh root@server sleep 100

After running the above, the sleep command is still running on the remote host.

Any ideas?

  • If it's any consolation, pretty much any task that writes to stdout will die due to a SIGPIPE (unless stdout is redirected on the remote host). – jdizzle Mar 10 '10 at 16:31

3 Answers3

1

Don't run it in the background in the first place. Thus, when the ssh conn dies, the process will be killed as well.

fim
  • 497
  • 2
  • 5
0

jdizzle's comment gave me an idea: run your commands inside a script and handle signals with "trap" (http://gd.tuwien.ac.at/linuxcommand.org/wss0160.php)

would that do?

cheers, eddy

Eddy
  • 296
  • 1
  • 10
0

Log back in through SSH , run a ps -ef | grep commandname and kill the process?