pkill -f can kill your own shell because -f matches the pattern against every process's full command line, and the shell running your command carries that command, pattern and all, as its argument. We had a command line containing pkill -f "electron-vite" die with exit status 137 and no log. A build that never started was reported as a failed one.
What happened
Mosaic's development loop restarts the app's dev server often, and the way to stop the old one is to kill electron-vite. A one-line command did that, then ran the build. The whole invocation ended with 137. No build output, no error, nothing written anywhere.
137 is 128 plus 9, so something was killed with SIGKILL. The build did not fail; it was never reached. What we recorded at the time is the mechanism, not the full process tree, so we cannot say which process in the chain was holding the string. What we can say is that the command line contained electron-vite, and so it matched.
Why pkill -f kills your own shell
Without -f, pkill matches a process's name. With it, pkill matches the whole argument list, which is what you want for node processes that all have the same name. The catch is that any process whose arguments contain your pattern is a target, and a shell started as bash -c "pkill -f electron-vite; npm run build" contains it.
pkill always leaves itself alone. What it does with the processes above it is where macOS and Linux part ways. We checked both on 3 November 2026.
On this Mac, man pkill says that by default "the current pgrep or pkill process and all of its ancestors are excluded", and -a includes them. The procps-ng manual used on most Linux systems says the running pkill "will never report itself as a match", and offers -A, --ignore-ancestors, as an option. The two defaults point in opposite directions, so a script that is safe on one can kill its own shell on the other.
We reproduced it on macOS with a marker string, putting the ancestors back with -a:
$ bash -c "sleep 0.1; pkill -a -f zzmark-q7; echo survived"; echo "exit=$?"
exit=143
The shell was killed before it could print anything: 143 is 128 plus 15, the SIGTERM a plain pkill sends. Without -a the same line printed survived. And ancestors are not the only risk. Anything beside your command that carries its text, such as a wrapper or a logger that was handed the command as an argument, matches regardless of either rule.
Everything the window does, from a script on your own computerIn Mosaic: REST API. Everything the window does, from your own scripts. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.
Mosaic is a desktop app
Email yourself the link and open it on your computer.
The fix: match on something only the target has
Our restart script now matches electron-vite and Electron by path:
pkill -f "$ROOT/node_modules/.bin/electron-vite"
pkill -f "$ROOT/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron"
$ROOT is the checkout's own path, read when the script runs, never written in. An earlier version had the old location hard-coded after the repository moved, so every kill matched nothing and the script started a second dev server, which quit at once on the single-instance lock. The path rule also stops a broader accident, because a bare pkill -f "Electron.app" matches every Electron app on the machine, ours among them.
When a path is not available, the bracket trick works. The regex [e]lectron-vite matches the text electron-vite in the target's arguments, but your own command line contains [e]lectron-vite, brackets included, which the regex does not match. We tested it with ancestors included:
$ bash -c "sleep 2; true" zzmark-q13 &
$ bash -c "pkill -a -f '[z]zmark-q13'; echo shell-survived"
shell-survived
target exit=143
The shell survived and the target was killed. Two more options are often better still: keep the process id when you start something and kill that id, or use pkill -P $$ to signal only the current shell's own children.
The same mistake with pgrep
pgrep -f matches the same way, and it has cost us more time than pkill. A loop waiting for build-chromium.mjs sync to finish polled pgrep -f "build-chromium.mjs sync", and the loop's own command line contained the string. It waited for itself, and an hour passed with nothing running. The first time this happened it was a wait on autoninja.py.
Waiting on a log line removes the problem entirely:
until grep -q "has finished" sync.log; do sleep 10; done
The log is written by the thing you are waiting for and by nothing else, so it cannot match the waiter. Waiting on evidence the target produces, rather than on a guess, is also the point of wait for a condition, not a sleep.
Before you kill by pattern
Run pgrep -lf "<pattern>" first and read the list. If your own shell, your editor or a wrapper is on it, the pattern is too wide. Our rule now is a path only the target has, because when a wide pattern goes wrong it reports nothing, and a run that ends silently looks like a broken build. We already lose enough time to slow ones: an app release is about seven minutes on a first run, and an engine build has its own disk and time budget.
Sources
- pgrep(1), procps-ng, Linux manual page, read November 3, 2026






