Ray's Knowledge Base
Unlock

pkill -f over ssh kills the ssh session when the pattern is in the remote command line

PitfallVerified 17 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

ssh host 'pkill -f run_queue.sh; ...' exits with code 255 and the rest of the remote command never runs; the target processes keep running.

Cause#

The remote bash -c '<whole command>' has the pkill pattern in its own argv, so pkill -f matches and kills the shell that runs it (and the ssh session) first.

Fix#

Put the pkill lines in a script file and run ssh host 'bash stop.sh', or use a bracket pattern such as pkill -f 'run_queue[.]sh', or kill by PID from ps. Kill the parent queue runner (for example xargs) before its children, or it starts new jobs.

Evidence#

2026-10-17 on linux7.cs.uchicago.edu: three ssh calls with pkill -f patterns exited 255; kill <xargs pid> then bash stop.sh worked.