Send SIGTERM to every process whose comm name is exactly worker.
Exclude worker-helper and use procps-ng pkill.
Which command is correct?
pkill combines process matching with signal delivery. -x requires an exact name and -TERM requests normal termination.
Detailed explanation
pgrep -x workerIncorrect. pgrep only prints matching PIDs.
Incorrect. pgrep only prints matching PIDs.
pkill -KILL workerIncorrect. KILL is forceful and the name is not restricted to an exact match.
Incorrect. KILL is forceful and the name is not restricted to an exact match.
pkill -TERM -x workerCorrect. It sends TERM only to processes whose name is exactly worker.
Correct. It sends TERM only to processes whose name is exactly worker.
kill -TERM workerIncorrect. kill -TERM expects a PID, not a process-name pattern.
Incorrect. kill -TERM expects a PID, not a process-name pattern.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'exec -a kp-worker sleep 0.2' & TASK_PID=$!; kill -TERM "$TASK_PID"; wait "$TASK_PID" 2>/dev/null || trueExpected result
出力なし。検証では安全のため既知PIDだけを終了Key points
- pkill searches and signals
- -x means exact match
- TERM is a graceful termination request
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.