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

Pause CPU hungry background applications System
Ever looked at your CPU utilization and wondered why some Carbon apps take a few percent of your CPU time even when they're not doing anything? It's typically because they poll for input (was there a click? was there a keypress?) in the traditional Mac style instead of using the new Carbon method of blocking until there is input. Some offenders: Internet Explorer, Adobe Acrobat, iCab, iTunes.

Here's how to pause and resume any process to get back this wasted CPU time, without having to quit and relaunch (and close open windows, etc.). You might even eek out a few more minutes of battery life.

On the command line, first get the PID of the process you want to pause; we'll use Explorer as an example:
  % ps -axww | grep Explor
2001 ?? S 7:55.67 /Applications/Internet Explorer.app...etc
The PID is the number in the first column, or 2001 in this case. To pause a process, send the STOP signal to its PID:
  % kill -STOP 2001
The process will become unresponsive until you send it the CONT (continue) signal:
  % kill -CONT 2001
This is a much nicer way to recover some spare CPU cycles without continually quitting and restarting applications.
    •    
  • Currently 4.17 / 5
  You rated: 5 / 5 (6 votes cast)
 
[14,835 views]  

Pause CPU hungry background applications | 5 comments | Create New Account
Click here to return to the 'Pause CPU hungry background applications' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Warning about network connections
Authored by: jalex on Aug 30, '02 11:12:00AM

This may be obvious, but I thought I'd point out that if you suspend (kill -STOP) a process that has an active network connection, the connection will almost certainly be dropped if you leave it stopped for any length of time. Like I said, this is only if it is something that keeps a connection open. An email program or web browser can be stopped since it only opens connections when it is checking mail or loading a web site, but a chat client or file transfer program will get disconnected if you suspend it. The actual length of time you can have it suspended depends on the protocol used... a general guideline is probably between 30 seconds and two minutes but that can vary widely.



[ Reply to This | # ]
Warning about network connections
Authored by: hombre on Aug 30, '02 02:05:34PM

I have found that it is possible to suspend downloads with wget for long periods and still be able to resume them, even if I have terminated and reconnected my internet connection. I have only used ctrl-z to suspend it (I am not sure if this differs from kill -STOP). Sometimes it takes a while to get going again, and sometimes it never does.



[ Reply to This | # ]
Warning about network connections
Authored by: delight1 on Jul 04, '07 04:31:05PM

... wget reconnects.... that is very different from normal programs...



[ Reply to This | # ]
Wake/sleep finder scripts available
Authored by: robg on Oct 02, '02 09:04:03AM
Anthony H. has made a set of scripts and downloads available which put this ability within easy reach of your Script Menu -- select "Sleep Word," for example, to put Word to sleep and then you'll see "Wake Word" in the Script menu to resume it. You can create script pairs for any application you wish. His scripts, along with a detailed Read Me which you should really read before doing anything else, can be found here: http://hydrology.rice.edu/SleepWake/SleepWake.zip Check them out if you'd like to make pause/resume accessible from the Finder! -rob.

[ Reply to This | # ]
New scripts...
Authored by: robg on Jan 04, '08 05:54:09AM
An anonymous user submitted a new hint about freezing and thawing background apps, but it's basically a duplicate of this hint -- except for these two shell scripts to ease the process. The user's hint submission follows...

==================================================

I wrote two scripts to "freeze" and "thaw" programs. It works on most, feel free to tweak.

FREEZE script:
#!/bin/sh

if [ $# != 1 ]; then
echo "Enter a program name to freeze such as "iTunes""
exit
fi

arg=$1

command=`ps auxwww | grep "$arg" | grep "/Contents/MacOS/"`

if [ "$command" ] ; then
process=`ps auxwww | grep "$arg" | awk '/Contents/ {print $2}'`

osascript <<END
tell application "System Events"
set visible of process "$arg" to false
end tell
END

kill -STOP $process
echo "$arg has been frozen."
else
echo "No process matching this name."
exit
fi
THAW script:
#!/bin/sh

if [ $# != 1 ]; then
echo "Enter a program name to thaw that has been frozen."
exit
fi

arg=$1

command=`ps auxwww | grep "$arg" | grep "/Contents/MacOS/"`

#Check if program is running

if [ "$command" ] ; then
process=`ps auxwww | grep "$arg" | awk '/Contents/ {print $2}'`
kill -CONT $process
echo "$arg is continuting as normal."
else
echo "No process matching this name. I will attempt to open it."
open "/Applications/${arg}.app"
exit
fi
Now I can simply use these two scripts to quickly freeze and thaw any program I wish -- I made an Automator script to do this to five programs at once. For instance, freeze Safari and thaw Safari.

==================================================

I tested these scripts, and they work as expected.

-rob.

[ Reply to This | # ]