pathikrit pathikrit - 3 months ago 34
Bash Question

Why does pkill kill my SSH session?

I want to do something like this:

program='java'
ssh bob@mycomputer "pkill -f $program; echo 'Done!'";


But, it seems like
pkill
is killing my ssh (I never see
Done!
). If I replace
pkill
with something else (say
pwd
), it works as expected.

Answer

Well seems really a good case here. The -f flag uses the full path of terminal and if its unable to get the process then it kills all the processes it could like pkill -f / which includes ssh. Refer here.

If you try pkill without -f then it works. You can also check ssh verbose (ssh -v) to see what is happening in the background.

Hope it helps.

Comments