pgrep -f self-match depends on the shell: bash/zsh exec a lone -c command, dash doesn't
Whether sh -c 'pgrep -f pat' (or ssh host 'pgrep -f pat') counts its own shell depends on the shell and the command shape. Tested with procps-ng 4.0.4: bash 5.2 and zsh 5.9 exec a single simple command given to -c, so pgrep -af qqzz alone has 0 self-matches (pgrep excludes itself), while pgrep -af qqzz; true has 1 because the shell stays around. bash also exec'd the last command of cd /tmp && pgrep .... dash 0.5.12 (Ubuntu /bin/sh) self-matched in both forms. So 'subtract 1' is wrong half the time. Use the bracket trick instead: pgrep -f '[q]qzz' matches the real process but not any argv containing the literal [q]qzz. It gave 0 false matches in all three shells and over ssh. When testing remote pgrep against localhost, remember that your local ssh client's argv also contains the pattern.