TASK_PID contains the PID of the target process.
Send SIGTERM rather than an immediate forced termination so the process can clean up.
Which command is appropriate?
SIGTERM is the conventional request for orderly termination. SIGKILL should be reserved for processes that do not respond, because it prevents cleanup.
Detailed explanation
kill -STOP "$TASK_PID"Incorrect. STOP suspends the process rather than requesting termination.
Incorrect. STOP suspends the process rather than requesting termination.
kill -CONT "$TASK_PID"Incorrect. CONT resumes a stopped process.
Incorrect. CONT resumes a stopped process.
kill -KILL "$TASK_PID"Incorrect. KILL is immediate and prevents normal cleanup.
Incorrect. KILL is immediate and prevents normal cleanup.
kill -TERM "$TASK_PID"Correct. It sends the requested SIGTERM to TASK_PID.
Correct. It sends the requested SIGTERM to TASK_PID.
Try it yourself
An example you can run in a temporary verification environment.
sleep 1 & TASK_PID=$!; kill -TERM "$TASK_PID"; wait "$TASK_PID" 2>/dev/null || trueExpected result
出力なし。sleepはSIGTERMで終了するKey points
- kill sends a signal to a PID
- TERM requests normal termination
- KILL prevents cleanup
Notes
- Environment: Bash 5.2 / procps-ng
- 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.