Two great signals: SIGSTOP and SIGCONT

The best uses I’ve found for the SIGSTOP and SIGCONT signals are times when a process goes haywire, or when a script spawns too many processes at once.

You can issue the signals like this:

kill -SIGSTOP [pid]
kill -SIGCONT [pid]

Wikipedia has great definitions for SIGSTOP:

When SIGSTOP is sent to a process, the usual behaviour is to pause that process in its current state. The process will only resume execution if it is sent the SIGCONT signal. SIGSTOP and SIGCONT are used for job control in the Unix shell, among other purposes. SIGSTOP cannot be caught or ignored.

and SIGCONT:

When SIGSTOP or SIGTSTP is sent to a process, the usual behaviour is to pause that process in its current state. The process will only resume execution if it is sent the SIGCONT signal. SIGSTOP and SIGCONT are used for job control in the Unix shell, among other purposes.

In short, SIGSTOP tells a process to “hold on” and SIGCONT tells a process to “pick up where you left off”. This can work really well for rsync jobs since you can pause the job, clear up some space on the destination device, and then resume the job. The source rsync process just thinks that the destination rsync process is taking a long time to respond.

In the ps output, stopped processes will have a status containing T. Here’s an example with crond:

# kill -SIGSTOP `pgrep crond`
# ps aufx | grep crond
root      3499  0.0  0.0 100328  1236 ?        Ts   Jun11   0:01 crond
# kill -SIGCONT `pgrep crond`
# ps aufx | grep crond
root      3499  0.0  0.0 100328  1236 ?        Ss   Jun11   0:01 crond

Comments

  1. says

    We had a similar problem when someone wrote C code to fork processes but due to some some bug it kept on creating processes.

    To stop the main process in its track, we had to login as the user as issue “kill -9 -1″

    I guess SIGSTOP would have helped.

  2. says

    These commands could be implemented into an easy to make easy to use and hopefully useful bash script.

    For those too lazy or who want to make it easy in case they forget the exact command (somehow)

    I think too much but whatever.

    -Kyle G

  3. jkelly says

    SIGCONT (kill -18 on Linux) is good for killing the dreaded zombie processes that just won’t die

  4. says

    Also useful for pausing a process that is writing a log file so that you can rotate the file without losing data. When you send the process a STOP, it quits writing data, you are then free to manipulate the file in any manner, such as copying it to another location, and then truncating it in order to free up disk space. When you are ready, send the CONT signal and the process continues writing as if nothing had happened.

  5. Tair says

    This tip was especially useful to simulate a long Java Garbage-collection pause, which is not a simple task on a dev machine where Java heap sizes are usually smaller.

  6. RAKK says

    Question: is it possible to send SIGSTOP to a kernel process?

    I’m asking, because I just discovered the hard way that Windows does lets you send its version of SIGSTOP to the System process… as you can imagine, this makes the entire system hang… and in this case, I don’t think the kernel should respond to a SIGSTOP.

  7. Abhijeet Joshi says

    Hello

    I am trying to run following commands in a script…

    bash sudo kill -18
    sleep 10
    bash sudo kill -19

    pid is 10304.. The script throws following error.

    bash: sudo kill -18 10304: No such file or director
    bash: sudo kill -19 10304: No such file or directory

    The same error occurs when I have tried to use SIGSTOP and SIGCONT instead of numbers 19 and 18.

    Any help on this is appreciated.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *