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.

Cputhrottle has worked for me in the past, though haven't checked it for 10.11 : http://www.willnolan.com/cputhrottle/cputhrottle.html