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
Printed from: http://rackerhacker.com/2009/06/15/two-great-signals-sigstop-and-sigcont/ .
© Major Hayden 2012.

3 Comments   »

  • Ace 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.

  • Kyle G. 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

  • jkelly says:

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

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this