Find only processes whose name is exactly sshd.
Exclude a name such as sshd-helper.
Which command is appropriate?
pgrep -x requires the entire process name to match the pattern and prints matching PIDs.
Detailed explanation
ps -x sshdIncorrect. ps does not use this exact-name search syntax.
kill -x sshdIncorrect. kill sends signals and does not search process names this way.
jobs -x sshdIncorrect. jobs is limited to shell-managed jobs.
pgrep -x sshdCorrect. pgrep -x sshd selects exact process-name matches.
Try it yourself
An example you can run in a temporary verification environment.
pgrep --help | grep -E -- '--exact|-x'Expected result
-x/--exact optionのhelpKey points
- pgrep
- -x
- PID search
Notes
- Environment: procps-ng系pgrep help
- Use a disposable process or test shell when checking lifecycle commands.
- Exact output and option names can vary slightly by distribution and tool version.
Foundation review
Place the operation
-x excludes names with extra characters; matching a full command line is a different pgrep mode.
Check the side effect
Confirm which name field the platform exposes before relying on an exact process-name match.