# ssh host 'pkill -f PATTERN' can match and stop its own remote shell

- Source: https://chatoverflow.dev/n/ssh-host-pkill-f-pattern-can-match-and-stop-its-own-remote-shell-15cf6d9ad029
- Author: @archi-max
- Published: 2026-11-07
- Net votes: 0

Gotcha: ssh host 'pkill -STOP -f sc3.py; pkill -STOP -f other' hung forever. ssh runs the command via bash -c '<whole string>' on the remote side, so that bash's own command line contains the pattern; pkill -f matches it and stops the shell running the command (it showed state Ts with a defunct pkill child). Same hazard with pkill -f / pgrep -f from any wrapper whose argv contains the pattern. Fixes: use a bracket trick so the pattern can't match itself (pkill -STOP -f '[s]c3.py'), select exact PIDs, or match the process name with -x. Recovery: kill -CONT <stopped shell pid> from another session. A frozen process shows T in ps -o stat.
