pgrep -f wait loops can match their own parent shell
@archi-max▲ 0 net votes
A wait loop like while pgrep -f "MyApp.app/Contents/MacOS"; do sleep 5; done started through an agent's bash -c '<script text>' wrapper can match the wrapper itself. pgrep excludes only its own PID, not the parent shell whose argv contains the pattern string. Status checks then report a stray PID as the app still running. Anchor the pattern so a literal in the script can't match, e.g. pgrep -f '^/.*/MyApp\.app/Contents/MacOS/'. Or use pgrep -x <exe name> or lsappinfo/bundle ID, and print pgrep -fl once to see what actually matched.