MacOS – Limit CPU when starting a task in terminal
cpumacosterminal
I'm working on an application for part of a school project that simulates an operating system and which I launch using the Terminal. By nature it will consume all possible resources to loop over and over. Is there a command or flag I can enter in Terminal to limit the amount of CPU it can utilize while it is running? I tried using the following command:
$ nice -n 20 ./a.out
to set the priority as low as possible, but it still took up 100% CPU to run. It's a rather simple program and hardly needs any resources to work properly so any limits imposed on it should be fine.
Best Answer
As nice only gives priority over over applications it won't stop 100% CPU usage.
Native Mavericks power management delivers the best combination of
processor and graphics performance and efficiency. The ingredients are
an installed processor specific power management ssdt, a compatible
system definition and the native power management kext. Native
Mavericks power management does not require specific BIOS settings or
anything more than one boot setting to load the power management ssdt.
Credit for the technique described to PikeRAlpha.
What changed between Mountain Lion and Mavericks power management? The
existing processor frequency/power state reporting tools (i.e.,
MSRDumper, HWMonitor) stopped reporting power states between idle and
max non turbo. This led to an incorrect conclusion that native
Mavericks power management was not working. A new tool, Intel Power
Gadget, shows Mavericks power management is working as designed.
To be clear, native Mavericks power management is not mandatory. The
consequences are not severe. Performance is similar, however, higher
temps (~10 C), more power (5-10 W) and sleep problems are likely.
Change Log
v1.1 - 4/4/14 - CPU PM/Core i3/5/7 xxx (1st Generation)/Core 2 and
earlier (below) v1.0 - 4/2/14: Initial Release
Requirements
OS X/10.9.2 or newer
Desktop/Laptop only
Server, see Guide: Asus X79 OS X Controlled SpeedStep
Stock Clock
Verify
OC, use ./ssdtPRGen.sh -f freq flag
Best Answer
As nice only gives priority over over applications it won't stop 100% CPU usage.
Cputhrottle has worked for me in the past, though haven't checked it for 10.11 : http://www.willnolan.com/cputhrottle/cputhrottle.html