Bash Command – How to Suspend and Resume Processes

bashcommand linejob-control

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

Best Answer

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]
Related Question