A background process was started in Bash and stopped with SIGSTOP.
Resume the same PID without starting a new sleep process.
sleep 600 &
TASK_PID=$!
kill -STOP "$TASK_PID"Which command is appropriate?
Sending SIGCONT resumes the same process after SIGSTOP. ps observes process state, while kill sends the signal that changes it.
Detailed explanation
kill -CONT "$TASK_PID"Correct. SIGCONT makes the stopped process runnable again without changing its PID.
Correct. SIGCONT makes the stopped process runnable again without changing its PID.
kill -TERM "$TASK_PID"Incorrect. SIGTERM requests termination; it does not resume the process.
Incorrect. SIGTERM requests termination; it does not resume the process.
nohup "$TASK_PID" &Incorrect. nohup starts a command and does not resume an existing PID.
Incorrect. nohup starts a command and does not resume an existing PID.
ps -p "$TASK_PID"Incorrect. ps displays process state but does not change it.
Incorrect. ps displays process state but does not change it.
Try it yourself
An example you can run in a temporary verification environment.
sleep 60 &
TASK_PID=$!
kill -STOP "$TASK_PID"
ps -o pid=,stat=,comm= -p "$TASK_PID"
kill -CONT "$TASK_PID"
ps -o pid=,stat=,comm= -p "$TASK_PID"
kill -TERM "$TASK_PID"Expected result
停止後: 状態欄の先頭がおおむね T
再開後: 状態欄の先頭がおおむね S
※環境により追加の状態文字が付きますKey points
- Getting the previous background PID with $!
- The roles of SIGSTOP, SIGCONT, and SIGTERM
- The difference between observing and changing state
Notes
- Environment:
- 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.