Extending Mac Activity Monitor with Process Suspend/Resume

I recently bought myself a MacBook Air. It’s my first Apple product ever, although I’ve been messing with their software before using PearPC and Hackintosh kinds of setups. Anyway, MBA as you know has an absolutely outstanding battery lifetime. Even without taking care about what and how you’re running you can usually squeeze out a couple of hours worth of energy from it. But if you actually DO pay a bit of attention to your CPU usage you might save an extra hour or so. In my case Firefox and Unity seem to always consume 5-10% of CPU also when I’m not doing even as much as hovering my mouse over their windows. I thought it would be neat to suspend them when I’m doing sth completely different like having a Skype call. So that’s reason #1.

Reason #2 – I also wanted to properly say “Hello!” to XCode, Objective-C, Cocoa, etc. and this trivial process suspend/resume thing seemed like a surprisingly good idea to do so. So what I was missing in Activity Monitor was essentially the possibility to send STOP/CONT signals to the selected processes. There is even a “Send Signal to Process” item in Activity Monitor’s view menu but… SIGSTOP is not on the menu (pun intended ;d). In any case I wanted it to be a bit more convenient, e.g. to have easily accessible buttons in the toolbar, so there was no question left in my mind that I had to act :]

The ways to modify a precompiled closed-source Obj-C application might seem a bit limited at the beginning but as you google a bit, everything becomes crystal clear. Obj-C binaries appear to contain quite rich runtime information about types and also there is an API to modify/extend all those classes on the fly by using regular Objective-C Runtime Library. So… with a bit of help from SIMBL which can inject your code into another process (in this case Activity Monitor) you have pretty good possibility to change the internal wiring of an application to suit all of your needs 🙂

Granted, there are already alternative process managers for Mac OS X which support process suspend/resume functionality. All of them however (at least to the best of my knowledge) are commercial software. Therefore, you might enjoy this free alternative which comes not as a separate application but as a useful extension of the well-known Activity Monitor.

You have to install SIMBL first and then uncompress the following bundle into /Users/<your_username>/Library/Application Support/SIMBL folder. After restarting Activity Monitor you should see two new buttons in the toolbar (as illustrated on the first screenshot). By selecting processes and clicking these buttons you can respectively suspend and resume the processes. If it doesn’t work out of the box try looking in the Console. Check out SIMBL website to learn what to look for and how to enable verbose debugging messages. You can also leave a comment with a complaint 🙂

I’m releasing the source code under New BSD license. For me it was really like my first “Hello world!” for Mac and for a “Hello world!” it’s a really nice project 😉

Hope everybody is having nice summertime like I do 😉 Enjoy!

DOWNLOAD: MacSuspendProcesses.bundle.zip
SOURCE CODE: MacSuspendProcesses.zip

Leave a Reply

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