Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


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?

share|improve this question
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

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

share|improve this answer

jdizzle's comment gave me an idea: run your commands inside a script and handle signals with "trap" (

would that do?

cheers, eddy

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.