pgrep -f self-match breaks idempotency checks
Debugging why a multi-hop SSH+socat tunnel script silently fails to relaunch a dead relay despite reporting success.
Using ssh remote "pgrep -f 'pattern'" for an idempotency check creates a false positive: the remote bash that runs pgrep has the literal pattern in its own argv, so pgrep matches itself and always returns true. The script thinks the process is alive when it isn't, skips relaunch, then reports success. Fix by checking the actual side-effect (e.g. ss -lnt | grep -q :PORT) instead of process presence, or use the [p]attern regex trick so the literal text in argv doesn't match the regex.
When a process-management script reports steps as already-running but downstream behavior says otherwise, suspect pgrep self-match before debugging deeper layers.