pgrep -f never reports its own process, but it can report a copy of the shell that is running it, and that is enough to wait forever. We had a loop waiting for an engine build step to end, polling pgrep -f "build-chromium.mjs sync". The step finished, nothing was running, and the loop kept seeing a match: its own command text. An hour passed before anybody noticed.

The loop

Tesseract Chrome, the Chromium that Mosaic runs, is built by one script with a step per stage. sync moves the source tree to a new Chrome version and can take a long time, so the next step waited for it like this:

while pgrep -f "build-chromium.mjs sync" >/dev/null; do sleep 30; done
node scripts/build-chromium.mjs patch

It looks right. -f is needed because every step is a node process, so the process name alone cannot tell them apart. But -f matches against the whole command line of every process on the machine, and the string build-chromium.mjs sync was now in two places: the sync step, and the command that was waiting for it. When the sync step finished, the second one was still there.

It cost us an hour, and it was the second time. The first was the same loop shape waiting on autoninja.py, the wrapper Chromium builds run ninja through.

Why pgrep -f matches itself

When a shell runs a command string, the shell process carries that string as its arguments: zsh -c 'while pgrep -f "build-chromium.mjs sync" …'. Everything that shell forks without running a new program (a subshell in brackets, a stage of a pipeline, a background job) is a copy of the shell with the same argument list. So the pattern you are waiting for is in the command line of every one of those copies.

Whether pgrep skips them depends on where you run it. On this Mac, man pgrep says "the current pgrep or pkill process and all of its ancestors are excluded" by default. The procps-ng manual used on most Linux systems promises less: "The running pgrep, pkill, or pidwait process will never report itself as a match." Ancestors are skipped there only if you pass -A (--ignore-ancestors). The letters do not carry over either. On macOS -a puts the ancestors back in; on Linux -a prints full command lines.

The fingerprint is changed inside the engine, not painted on topIn Mosaic: Fingerprints set inside the browser. Tesseract Chrome: values set inside, not by a script. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

How it works: Fingerprints set inside the browser

What we could reproduce, and what we could not

We tried it on macOS in November 2026 with a marker string nothing else runs. The plain case is safe here, because the shell is an ancestor and gets skipped:

$ zsh -c 'pgrep -fl "zzq-nothing-runs-this"; echo "exit $?"'
exit 1

Fork one copy of the shell first and the same pattern finds it:

$ zsh -c '( sleep 3; true ) & sleep 0.5; pgrep -fl "zzq-nothing-runs-this"'
68581 zsh -c ( sleep 3; true ) & sleep 0.5; pgrep -fl "zzq-nothing-runs-this"

That match is a sibling, not an ancestor, so the macOS rule does not cover it. Running the same line again under bash a few seconds later listed two matches, the new subshell and the one left over from the zsh run, which was still sleeping. A leftover from an earlier attempt is a match too, so retrying the same wait makes it worse.

We did not keep the process tree from the hour we lost, so we cannot say which copy held the string. The two plain loop shapes we tried on the Mac both returned. Our notes record a waiter whose pattern was in its own command text, and a step that had ended an hour earlier. On Linux the plain loop alone is enough, because the shell running it is not excluded.

Wait on the log, not on a pattern

The rule we wrote down afterwards is short: never wait on a pgrep pattern your own command line contains. Wait on something the job writes instead:

( node scripts/build-chromium.mjs sync > sync.log 2>&1; echo "sync exit $?" >> sync.log ) &
until grep -q "^sync exit" sync.log; do sleep 30; done

The line sync exit 0 is written once, after the step ends, by the step's own shell, so nothing else can produce it and the waiter cannot match itself. It also says how the step ended, which a vanished process does not. The same idea, applied to timing in tests, is in wait for a condition, not a sleep.

Three other ways work when a log is not available:

  1. If your script started the process, keep $! and call wait on it, or poll kill -0 "$pid". A pid is exact and matches nothing else.
  2. Use the bracket form, pgrep -f '[b]uild-chromium.mjs sync'. The regex matches the target, and your own command line contains [b], which it does not match.
  3. On Linux, add -A so pgrep skips its ancestors. That covers the shell, not its siblings.

Before trusting any pgrep -f wait, run pgrep -lf "<pattern>" once and read the list. If your own shell is on it, the wait will never end. pkill -f has the same habit with worse results, because a match is killed rather than waited on (the pkill story has the exit code and the fix). When a step can take as long as an engine build does (the disk and time budget for one is large), a waiter that cannot end costs real hours.

Sources

  1. pgrep(1), procps-ng, Linux manual page, read November 3, 2026