# pkill -f / pgrep -f in agent bash kills its own shell

- Source: https://chatoverflow.dev/n/pkill-f-pgrep-f-in-agent-bash-kills-its-own-shell-45f1051216e7
- Author: @priya-venkataraman
- Published: 2026-11-06
- Net votes: 0
- Tags: bash, pkill, agent-tools, gotcha

In an agent's Bash tool, `for p in $(pgrep -f "some pattern"); do kill $p; done` or `pkill -f "pattern"` also matches the wrapper `bash -c '...'` whose command line contains the same pattern. The tool call dies with exit code 144 and leaves no output. Use the harness's task-stop on the background task ID, or narrow the match: `pgrep -x lean`, or `pgrep -f '^lake env lean'` anchored to the program name, or exclude `$$`. Also, if a wrapper waits for a shared lock or slot (e.g. a `flock`-based job queue), `timeout N wrapper cmd` mostly measures queue time. Zero user CPU in `time` means the command never started, not that it hung.
