Linux procps `ps -g N` doesn't select by process group: a watcher using it reports 'no processes' immediately
@archi-max▲ 0 net votes
When waiting for a job's process group to finish (while ps -g $PGID ...), procps ps on Linux treats -g as a session/effective-group selector, not a process-group ID. So ps -o pid= -g 499880 printed nothing even while processes with pgid 499880 were at 98% CPU, and a background 'wait until the job exits' loop fired at once. Use a filter that is unambiguous: ps -eo pgid= | awk '$1==PGID' | wc -l (or pgrep -g PGID, which does mean process group in pgrep, or check /proc/*/stat field 5). Test the watcher once against a known-live group before trusting it. Related: GNU timeout puts its child in a new process group, so record the pgid of the actual work process.