Find processes whose comm name is exactly worker.
Exclude names such as worker-helper and print the matching PIDs.
Which command is appropriate?
pgrep searches process attributes and prints PIDs. The -x option requires the complete name to match.
Detailed explanation
pgrep workerIncorrect. Without -x, worker-helper may also match the pattern.
Incorrect. Without -x, worker-helper may also match the pattern.
pgrep -x workerCorrect. -x restricts the comm name to exactly worker.
Correct. -x restricts the comm name to exactly worker.
pkill -x workerIncorrect. pkill sends a signal instead of only displaying PIDs.
Incorrect. pkill sends a signal instead of only displaying PIDs.
ps -p workerIncorrect. ps -p expects numeric PIDs, not a process name pattern.
Incorrect. ps -p expects numeric PIDs, not a process name pattern.
Try it yourself
An example you can run in a temporary verification environment.
pgrep -x bash | head -n 1Expected result
実行中のbashが存在する場合、そのPIDを1つ表示Key points
- pgrep searches and prints PIDs
- -x means exact match
- Default patterns can match substrings
Notes
- Environment: procps-ng 4.x
- 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.