How to Limit Mac CPU Usage for an App | PassGap Tips

It was discovered a long time ago that Activity Monitor on Mac is really just a pure monitoring service and cannot be set manually by the user to prioritize processes like  Task Manager on Windows OS. But what do we do when we really need to limit Mac CPU usage for a specific app?

As we know, Apple’s macOS is a half-open and half-closed operating system. Broadly speaking, GUI layer is a close source, which is the essence of macOS; the core system (darwin-xnu) is open source. This allows users or developers to  have the opportunity to make system calls to fulfill a requirement – to limit the CPU usage of a process or app.

Perhaps you are wondering, what kind of people would have this need? You have this need when some companies force their employees to install "xx security software" and from time to time it scans files in the background and eats CPU like crazy, and you are not allowed to close and uninstall it.

 

Method 1: cputhrottle

This tiny tool has no GUI and is a lightweight utility based on command line. The developer provides the source code and compiled binary executable on its official page. I thought this old OS X style software was no longer working on current versions of macOS, but to my surprise, it is still working on latest macOS Monterey like a charm if you want to limit CPU usage on Mac , probably due to the good compatibility with stable kernels (Basically, there is no OS kernel that changes system calls regularly).

After downloading cputhrottle.gz and unpacking it, open Terminal app and grant permission to run this app.

chmod +x cputhrottle

Now, find the pid of running apps with ps command:

ps -ef

Once you get the pid of an app,  enter the below command to limit the CPU usage of the app. The first parameter is the pid of the process, the second parameter is the maximum CPU usage percentage, suppose a security software process id is 7218, you only allow it to eat up to 50% of entire CPU.

sudo ./cputhrottle 7218 50

This will ensure that it is not killed and does not slow down your Mac, so it can be called "not to die, not to live". To make it easier to use, we can put the executable under /usr/local/bin, so that it can be executed directly in any directory later.

mv cputhrottle /usr/local/bin

However, after executing the command, the program will occupy the current terminal because of its internal dead-loop logic. A more elegant approach would of course be to let it go to the background and execute it without affecting the continued use of our terminal.

If you find the approach cumbersome, you can also use the nohup command directly.

sudo nohup cputhrottle 7218 50 &

You can kill the app when you no longer need to limit the CPU usage of the 7218 process.

sudo kill 7218

Since the source code of cputhrottle is relatively small,  then I dig into it a little bit and found that the core logic is  not complicated. It samples the CPU usage time of the specified process, calculate the percentage of control, and finally hang the task through a system call and hibernate for a certain amount of time to achieve the goal of freeing up CPU resource.

 

Method 2: AppPolice

The above solution is relatively primitive.  This is good for users who are more familiar with Terminal, and it is also suitable for those who like to write their own command scripts. All of the later programs shared in this post are software with GUI,  more suitable for ordinary users.

AppPolice, like cputhrottle, is also open source app, a 2016 vintage software. However, it is still usable on new Macs. Please download dmg from its GitHub repository, install it and you’re good to go.

After opening AppPolice app, you can directly control CPU usage on Mac each application process, the maximum is unlimited, compared to the command tool, it is indeed still very convenient. In my example, I limit the CPU usage to 50% for FireFox browser.

apppolice

 

Method 3: App Tamer

App Tamer software is not open source but a paid software.  The UI and features  looks a little more mature than AppPolice. After installation, the first time you open it, you will be prompted to install the helper tool to make it working correctly.

There is a guide page on the first screen, which introduces some basic functions. In fact, it is similar to AppPolice that you can manually limit the maximum CPU usage of each app on Mac.

App Tamper

It also provides a global switch to turn off restrictions when you don’t have to exit and turn them on when you need them. The various features are also much richer, but basically I’m done with this one screenshot.

App Tamer Limit CPU

 

Method 4: Turbo Boost Switcher

Strictly speaking, this app is not the same as the above three. The main feature is to enable or disable Intel processor Turbo Boost on demand. For reference, Turbo Boost is based on Intel’s Raid technology for  automatic overclocking. The trick in here is to put the processor in a low frequency state in order to save power.

turbo boost switch

Hence it is not used to limit Mac CPU usage. Instead, it is for global energy saving. I think it is quite amazing so I put it here.

Leave a Comment