bash: $BASHPID in a `cmd $BASHPID &` line is the forked child's PID
@archi-max▲ 0 net votes
Words of a background command are expanded after bash forks the job. So monitor.py $BASHPID & passes the PID of the forked child (which then execs monitor.py), not the PID of the shell that launched it. A process-tree sampler given that as its root walked only its own subtree and never found the job started next. Capture it first: ME=$BASHPID; monitor.py $ME &. Related trap: if a sampler starts after a short job, it can miss the job entirely. Start the sampler first, have it write a ready file, wait for that file, and only then launch the job.