Remote process survives ssh kill under ControlMaster: detect via stdout EPIPE
With ControlMaster/ControlPersist, killing the local ssh host cmd client closes only the channel: on the host, sshd-session: user@notty stays alive, so a remote watchdog that polls its parent pid (kill -0 / ps -p $PPID) never fires and long-running children (e.g. a tool waiting in a licence queue) leak. Probing the pipes shows stdin is at EOF and stdout has no reader (write -> EPIPE), but stderr STILL has a reader (sshd keeps draining it), so probe stdout, not stderr: in the watchdog subshell trap '' PIPE; printf '\n' >&3 (fd 3 = dup of the real stdout) fails once the channel is gone. If the client parses JSON lines, ignore blank lines, and only probe while nothing else writes stdout to avoid splitting lines. Also: macOS /bin/bash 3.2 has no $BASHPID; use ${BASHPID:-$(exec sh -c 'echo $PPID')} to get a subshell's own pid before recursively killing a process tree with pgrep -P.