Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Suspend and resume any program using SIGSTOP UNIX
If you've ever been running a program that requires a lot of CPU or hits the disk heavily, and then wanted to be able to use your computer for something else for a few minutes, this is the hint for you.

Most UNIX people know they can use Control-Z and the bg and fg commands to control whether or not their programs are running. What many often don't know is that you can do the same thing using signals. For instance, let's say I am doing a long build in Project Builder, but I need to use my computer for a few minutes at full speed to do something else. Here's how to accomplish that:
  1. Find the process ID of the program you want to suspend using either the ps wwwaux command from the shell or via Process Viewer (in /Applications -> Utilities):
    /Users/sam:> ps auxwww | grep Project
    sam        814   0.0  0.6   114984   5900  ??  S     4:24PM
      0:01.56  /Developer/Applications/Project Builder.app/
      Contents/MacOS/Project Builder -psn_0_5636097
    
    Here the id is 814 (line breaks were added above for narrower display width).

  2. Use the kill command and send it a SIGSTOP signal:
    /Users/sam:> kill -SIGSTOP 814
    
    The program will now stop doing whatever it was doing and you can then do a quick render or whatever it was that needed the whole machine.
To resume your program right back where it was, just use the kill command and send it a SIGCONT signal:
/Users/sam:> kill -SIGCONT 814
It's as easy as that. I'm sure some enterprising individual could make a graphical program that does this for you, but I'm a UNIX user at heart.

[robg adds: A previous hint explains a different method of pausing applications.]
    •    
  • Currently 2.43 / 5
  You rated: 1 / 5 (7 votes cast)
 
[22,442 views]  

Suspend and resume any program using SIGSTOP | 20 comments | Create New Account
Click here to return to the 'Suspend and resume any program using SIGSTOP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
priorities
Authored by: SOX on Sep 18, '03 11:01:35AM

What I would like is some way of setting priorities on jobs. I've tried the ways I'm used to in linux using top and nice and renice and they dont seem to have an effect. Not sure why.



[ Reply to This | # ]
priorities
Authored by: englabenny on Sep 19, '03 02:04:40PM

renice works for me, even though I don't use it. I tried for example to set Window Manager to very hight priority, and iTunes to very low. Dragging windows heavily around then compromised soundplay.



[ Reply to This | # ]
Re: priorities
Authored by: sjk on Sep 20, '03 12:40:30AM
IIRC subprocesses will inherit the nice priority of their parent process. Run ps alwwx and check the NI column to check that.

[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: AviDrissman on Sep 18, '03 11:47:27AM

I think that's the same as the old hint. SIGSTOP and STOP are just two names for the same signal. Same for SIGCONT and CONT.



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: jtalkington on Sep 18, '03 12:40:15PM

Yes, that is correct. The signal names are SIGSTOP and SIGCONT, but kill lets you use shorthand for all the signals (by dropping the SIG in front.) You could also use the signal numbers (17 and 19, respectively,) which are all listed in /usr/include/sys/signal.h .



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: Mattbot on Sep 18, '03 01:46:03PM

The SIGSTOP and SIGCONT signals work in bash and sh while only STOP and CONT seem to work in all the other shells I've tried. (csh, tcsh, zsh) Bash and sh can do it both ways as stated above.



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: jacobolus on May 17, '06 09:23:28AM
That doesn't make sense, because it's the same kill program getting the arguments either way.

[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: Mattbot on May 24, '07 05:58:23PM

Kill is a built-in shell utility, not a stand alone binary. Run this command:

which kill

And you get:

kill: shell built-in command.

[ Reply to This | # ]

Suspend and resume any program using SIGSTOP
Authored by: adamprall on Sep 18, '03 04:19:18PM
I found that on my system, I cannot use the "SIG" prefix, I just ket an "SIG: Unknown signal" error, so on my machine I use:

kill -STOP number

or

kill -CONT number

[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: gatorparrots on Sep 19, '03 12:01:57AM
Here are zsh functions so one can automate the process in the terminal. Simply stop [processname] and then cont [processname]. (Note: due to the ambiguity of LaunchCFM applications' process names, it's an all-or-nothing proposition: you would have to pause all such Carbon apps with stop CFM, then cont CFM):
##------stop/continue processes------##
stop () {
	PID=$(ps auxcww | grep -i "$1" | awk '{print $2}');
	mkdir -p /tmp/run;
	echo "$PID" > /tmp/run/"$1".pid;
	kill -STOP $PID;
}
cont () {
	kill -CONT $(cat /tmp/run/"$1".pid);
	rm /tmp/run/"$1".pid;
}


[ Reply to This | # ]
2nd method handles Carbon apps
Authored by: gatorparrots on Sep 19, '03 12:23:48AM
Normally I prefer to limit ps output by using the u and c flags, thus avoiding the need for the second grep process and another pipe. In this case, however, it seems best to add a bit of inefficiency for the sake of functionality. These functions can now handle Cocoa and Carbon apps by (case-insensitive) name. For example, stop entourage and cont entourage now works.
##------stop/continue processes------##
stop () {
	PID=$(ps axww | grep -i "$1" | grep -v grep | awk '{print $1}');
	mkdir -p /tmp/run;
	echo "$PID" > /tmp/run/"$1".pid;
	kill -STOP $PID;
}
cont () {
	kill -CONT $(cat /tmp/run/"$1".pid);
	rm /tmp/run/"$1".pid;
}
     

[ Reply to This | # ]
2nd method handles Carbon apps
Authored by: bluehz on Sep 19, '03 07:04:26PM

Is it possible to setup an external functions library for sourcing in tcsh shell? I have a few function including the above, that I would like to make available to every shell so I would like it sourced with the inits. Is it even possible in tcsh?

And yes - I know - I should switch to Bash or zsh, BUT since I still consider myself a novice shell scripter and damn near every example (from which I learn) is in sh - I think I will stick with tcsh for a while longer.... hence my request.



[ Reply to This | # ]
zsh functions ?
Authored by: mug1 on Sep 19, '03 04:34:06AM

where to you put zsh function definitions in order to be able to use them on the command line? it is not the .cshrc, is it?
(might be obvious to most of you... for some maybe it isn't)


---
----
chris



[ Reply to This | # ]
zsh functions ?
Authored by: gatorparrots on Sep 19, '03 01:40:15PM
With zsh you can put the functions just about anywhere you like:
       Commands  are  then  read  from  $ZDOTDIR/.zshenv.  If the
       shell is a login shell, commands are read from  /etc/zpro-
       file  and  then $ZDOTDIR/.zprofile.  Then, if the shell is
       interactive, commands are read from  /etc/zshrc  and  then
       $ZDOTDIR/.zshrc.   Finally, if the shell is a login shell,
       /etc/zlogin and $ZDOTDIR/.zlogin are read.

       If  ZDOTDIR  is  unset, HOME is used instead.  Those files
       listed above as being in /etc may be in another directory,
       depending on the installation.
These functions should also work under the bash shell, but I have not tested them in that environment.

[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: calroth on Sep 19, '03 09:28:40PM

killall -SIGSTOP [processname]

killall -SIGCONT [processname]

Easier.



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: sjk on Sep 20, '03 12:45:22AM
killall -STOP [procname ...]
killall -CONT [procname ...]


Sans "SIG" easier. :-)

[ Reply to This | # ]
Useful for internet hogs as well
Authored by: zeb on Sep 19, '03 12:10:55PM

Just thought I'd mention that this also works great for stopping an app using all your bandwidth... say a download. I often want to stop a download in Safari while I check my email in Entourage. - Though I usually don't stop it for very long since I want to avoid any sort of timeout... not sure if this would really be an issue though.

---
..:: Zeb ::..

zebellis.com



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: englabenny on Sep 19, '03 03:14:48PM

This is a golden hint!

I wanted to do a wrapper around the suspend and resume features of the command line, but I did not succeed. Well, now I just threw together a quick hack and it works! Thanks.



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: birty on Sep 21, '03 04:59:14AM

I use Horse Menu to perform those actions
http://www.nimatoad.com/HorseMenu/index.html

Hopefully it will still work in Panther



[ Reply to This | # ]
Suspend and resume any program using SIGSTOP
Authored by: jacobolus on May 17, '06 09:24:57AM

Quicksilver works great for this.



[ Reply to This | # ]