Friday, May 31, 2013

Pause and Resume an App or Process in Mac OS X

7:08 AM

Need to quickly free up some processing power? You can do that easily by temporarily pausing and then later resuming any active process or application in Mac OS X. Technically, this is actually ‘stopping’ and ‘continuing’ a process, but a stop is not to be confused with the more aggressive killing or force quitting applications and thus the terminology of pausing or halting is often easier to differentiate the two.

This means you can take a process that is consuming 100% CPU and temporarily pause it while you do something else, then resume it when you are ready to let that process do it’s thing. This is achieved through a command line trick, and we’ll cover two different ways to do it by using the kill and killall commands with the -STOP and -CONT flags. Ideally you will have some comfort and knowledge with the command line before using this, but it’s certainly not necessary.

Before beginning, launch the Terminal app, found in /Applications/Utilities/, and also launch Activity Monitor, which is in the same folder.

How to Temporarily Suspend Stop a Process or App in Mac OS X

The basic syntax for suspending an application is as follows, where PID is the ID of the process you wish to pause:

kill -STOP PID

The PID is always a number, and every single process running on a Mac has an associated ID.

If you’re familiar with retrieving process ID’s, then you already know what to do using the above commands alone, but if not then that’s what we’ll cover next, and that’s why we launched “Activity Monitor”

Finding the PID & Halting the Associated Process

This is the more user friendly method, utilizing Activity Monitor:
  • From Activity Monitor, use the Search function in the upper right corner and type the application name you wish to suspend (e.g.: iTunes)
  • With the matching processes and/or app(s) visible, locate the process ID by looking under the “PID” column
  • Add the matching PID to the aforementioned kill command, like so:
kill -STOP 3138
  • Note the CPU activity for that process ID is now at 0%, indicating the process has been paused (technically, stopped)
Don’t forget the PID, or better yet, don’t close the Terminal window quite yet, because that same PID is how you will resume the application to continue being able to use it again.

You will find the effect of stopping a process on CPU usage is dramatic, this screen shot demonstrates iTunes consuming 70% CPU while running it’s Visualizer, and the same iTunes process after it has been halted with the -STOP flag. The process has literally been stopped in its tracks:

Those with more command line knowledge may prefer to use ps rather than Activity Monitor, which is really quite easy:

ps aux |grep Name

Change “Name” to whatever the start of a process or application name is, locate the PID, and then put that into the kill command:

kill -STOP 92841

Whether you use Activity Monitor or ps to retrieve the PID is irrelevant, so long as you enter the correct process ID when using the kill command.

Note that trying to use an application that has been paused will almost always result in seeing the spinning beach ball of death, minus the CPU usage. Thus, if you want to use the app again, you must “resume” it.

How to Resume a “Stopped” Application or Process
Resuming a stopped or paused application is simple, just change the kill command slightly and use the same process ID that you retrieved from the previous steps:

kill -CONT PID

For example, to resume the iTunes app using the PID from earlier:

kill -CONT 3138

And now iTunes becomes usable again, minus the spinning wait cursor. Along with this comes a return to whatever level of CPU consumption existed earlier.

The screenshot below demonstrates this trick using both the kill and killall commands:

Using -STOP and -CONT with killall is essentially the same, but it has some limitations regarding names, and thus we covered the more direct method of using kill based on PID instead. Nonethless, let’s demonstrate this with killall too.

Stopping & Continuing Applications by App Name

If you know the application or exact process name, you can also use the ‘killall’ command with the -STOP flag to halt processes. This can be easier for apps that are simple to identify by a name, but it has limitations when it comes to working with processes with complex names, or for pausing a specific process that has duplicate processes with the same name (like a specific Chrome tab or window mixed in with many “Google Chrome Renderer” processes), and thus we covered the PID approach first because it’s much more direct.

The basic halt command with killall is as follows:

killall -STOP AppName

Not sure what the app name is? Use ps and grep:

ps aux |grep AppName

For example, you could grep for “Chrome” to find all processes with “Chrome” in the name:

ps aux|grep Chrome

Or you can just target the process with a specific app name like so:

killall -STOP -c "Google Chrome"

Resuming processes and apps with killall is a matter of changing the flag from -STOP to -CONT, everything else is the same:

killall -CONT AppName

For example, to resume the application with a long name:

killall -CONT -c "Google Chrome"

Again, the app/process will continue to function as usual, and CPU usage will return to where it was before being paused.

Apps or processes with no spaces in their name can be impacted directly by killall without any additional flags or indicators, like iTunes.

Note: If this Tutorial and News worked for you (and it should work), please leave a comment below. Thanks.

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 iFlasha. All rights resevered. Designed by Templateism

Back To Top