How to suspend and resume processes

In the bash terminal I can hit Control+Z to suspend any running process… then I can type fg to resume the process.

Is it possible to suspend a process if I only have it’s PID? And if so, what command should I use?

I’m looking for something like:

suspend-process $PID_OF_PROCESS

and then to resume it with

resume-process $PID_OF_PROCESS
Asked By: Stefan

||

You should use the kill command for that.

To be more verbose – you have to specify the right signal, i.e.

$ kill -TSTP $PID_OF_PROCESS

for suspending the process and

$ kill -CONT $PID_OF_PROCESS

for resuming it. Documented at 24.2.5 Job Control Signals.

Answered By: maxschlepzig

You can use kill to stop the process.

For a ‘polite’ stop to the process (prefer this for normal use), send SIGTSTP:

kill -TSTP [pid]

For a ‘hard’ stop, send SIGSTOP:

kill -STOP [pid]

Note that if the process you are trying to stop by PID is in your shell’s job table, it may remain visible there, but terminated, until the process is fg‘d again.

To resume execution of the process, sent SIGCONT:

kill -CONT [pid]
Answered By: Steve Burdine
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.