Unix tip: kill -STOP and kill -CONT

Pretty much every Unix user knows about the kill command, and most know about ‘kill -KILL’ aka ‘kill -9’.

But do you know about kill -STOP and kill -CONT?

I’m not sure of the exact mechanism (kernel vs. user process) but everything I’ve used it on on a Mac OS X machine has responded to it in the same way. So you may find a process that doesn’t do this, but I haven’t found one.

Basically kill -STOP 1234 will pause the process with pid 1234, and kill -CONT 1234 will resume it. It’s as if you can sleep individual applications instead of your entire computer.

It’s simple, but you can probably imagine why this would be useful. Want to keep Firefox with 45 tabs open, but you’re not using it for a while and you want to save battery life? Pause it. Pretty much anything like “I don’t want to quit and then re-launch this but I wish it wasn’t using a bunch of CPU time while it idles” is a good candidate.

Remember that this means your app my time out when it is resumed, as if you had slept your laptop. So network connections it had open when you paused it may be broken when you resume it. So pausing Terminal.app with a bunch of open ssh connections to remote servers isn’t going to work too well.

5 thoughts on “Unix tip: kill -STOP and kill -CONT”

  1. Gotta love STOP and CONT! I made some simple bash functions to help me out, so I can type something like “stop firefox” at the prompt.

  2. Made a little bash script to toggle the state of the active window:
    #!/bin/bash
    myid=$(ps $(xdotool getwindowfocus getwindowpid) |tail -n 1 |awk ‘{print $3}’)
    if [[ $myid == “Sl” ]]
    then
    kill -STOP xdotool getwindowfocus getwindowpid
    else
    kill -CONT xdotool getwindowfocus getwindowpid
    fi

  3. CTRL-Z => stoppe l’appli
    fg => la reprend en arrière plan
    bg => la ramène au premier plan

    Le kill -stop reste bien utile pour les processus sans console.

  4. J ene peux éditer mon précédent commentaire.

    Le bon ordre des choses:

    bg => la reprend en arrière plan
    fg => la ramène au premier plan

Leave a Reply

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