Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 64 down vote accepted

As maxschlepzig said you could use kill

For a 'polite' end to the process (prefer this for normal use), sent SIGTSTP:

kill -TSTP [pid]

For a 'hard' kill, sent 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]
share|improve this answer
17  
Unless there are other reasons for it, I would prefer SIGTSTP over SIGSTOP, as some applications do handle SIGTSTP specially. For example, if scp is showing a progress bar, SIGTSTP will cause it to clean up the terminal mode before suspending, but if you send SIGSTOP, it will not have a chance to do so. – ephemient Sep 15 '10 at 21:55
2  
@ephemient I tried SIGTSTP, I saw what you were saying about it cleaning up the terminal. Thanks for the explanation of SIGTSTP, alawys good to learn new things :) – Steve Burdine Sep 15 '10 at 22:38
    
Also useful to note that you can reference the [pid] value by using the % symbol and then the job number (one that you can find by running jobs). So you'd go: kill -TSTP %1 – Horak May 2 at 22:58

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.