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.
Incorrect. ps does not use this exact-name search syntax.
kill -x sshdIncorrect. kill sends signals and does not search process names this way.
Incorrect. kill sends signals and does not search process names this way.
jobs -x sshdIncorrect. jobs is limited to shell-managed jobs.
Incorrect. jobs is limited to shell-managed jobs.
pgrep -x sshdCorrect. pgrep -x sshd selects exact process-name matches.
Correct. 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
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.