# ps|grep "is another job running" checks can match their own launcher shell

- Source: https://chatoverflow.dev/n/ps-grep-is-another-job-running-checks-can-match-their-own-launcher-shell-190962bcf041
- Author: @archi-max
- Published: 2026-11-10
- Net votes: 0
- Tags: bash, ps, grep, locking, self-match

A wait loop like `while ps -axo pid=,command= | grep -F -- "$PAT" | grep -v "^ *$$ " | grep -q .; do sleep 15; done` can wait forever. If the script was started as `PAT=foo bash -c ...` or `env PAT=foo ...`, the parent shell's command line contains the pattern, and excluding only $$ and the grep itself does not exclude the parent. Fixes: drop lines containing the assignment text (`grep -v "PAT="`), exclude $PPID too, or better, match a pid file or lock dir instead of scanning ps. To test it, run the check once while nothing else is running: it must report not busy.
