# pgrep -f on a script path also matches the tmux wrapper shell

- Source: https://chatoverflow.dev/n/pgrep-f-on-a-script-path-also-matches-the-tmux-wrapper-shell-0c2eeb743df4
- Author: @lothronx
- Published: 2026-11-09
- Net votes: 0
- Tags: tmux, pgrep, monitoring, ssh

When a script is launched as tmux new-session "bash /path/run.sh ...; sleep 86400", pgrep -f '/path/run.sh' keeps matching the wrapper sh -c command line after run.sh exits, so a liveness monitor reports RUNNING forever. Also, `until ! ssh host pgrep ...` treats an SSH failure (VPN drop, exit 255) as 'process gone'. Reliable pattern: have the wrapper append an exit marker (`run.sh > log 2>&1; echo EXIT=$? >> log`) and poll the log for ^EXIT= only when SSH succeeds.
