Is there any way to set the priority of a process in Mac OS X?
Solution 1
From the command line (Terminal.app
or whatever) use nice
and renice
, just like on other unixes.
Use nice
when launching a process:
nice -n <priority> <command> <arguments to command>
The default priority is zero, positive values are "nicer" (that is lower priority) and negative values are "less nice" (higher priority). Looks like Mac OS runs from +10 to -10.
Use renice
to change the priority of a process already running (from the renice
man page on 10.5):
renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]
renice -n increment [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]
The part you're interested in here is the pid
bit. That is the process id for the job and you can find it using ps -u <your username>
and looking for the process name, but I prefer top -o
in this case, because the process you're interested in will be near the top.
Note: Without superuser privileges you can never increase a process's priority. For normal users, nice
and renice
are one way streets. And small changes in priority can have large effects on running time. So go easy on this until you understand it.
Solution 2
You can use the command:
renice -n # PID
Where:
- # is a number that should be larger than 0 (otherwise you will move your process to higher priority)
- PID is the process ID you can view by typing
top
on the terminal app (utilities/terminal.app)
If it is a system process or another user process you should type:
sudo renice -n 10 PID
It will ask you for your password (if you are sudoer). As for the number I would recommend 10 or 19 (even lower priority).
Note that this will change the priority not the CPU usage. If you aren't running other processes which require CPU or you have more than one CPU on your Mac (Core 2 Quad Core) the process might still use 100% of CPU.
Solution 3
renice 20 $(pgrep ImageOptim)
Or use the name of your program instead of ImageOptim
Solution 4
If your process is an app or app helper utility rather than a system process and you don't want to do
nice
orrenice
on every system boot you can give it a shot to AppPolice. It's open source and free. You can download it here, or install it with the homebrew commandbrew cask install AppPolice
Another alternative would be a very nice command line task manager GUI called
htop
. You can see all the processes and tune theirnice
values byF7
and andF8
shortcuts. (Please note that negativenice
values are more prioritized and opposite for positive values)
To install it:
- Install homebrew if you don't have it yet.
- Run this command
brew install htop
in Terminal - Now you can do
htop
to see and manage processes in Terminal orsudo htop
to cover all the system.
Solution 5
There are also a number of GUI utilities, like the free BeNicer and Process Wizard (my previous favorite), and the $1.99 version of Freezer, which is my new favorite. These all work on running applications.
Related videos on Youtube
Daniel Cukier
Daniel is a technology innovator, currently exploring web3 projects. Former CTO in Brazilian startups such as Pravaler - a fintech that offers accessible student loans - also founder and CTO at Playax - an audience development platform for music professionals based on BigData - he also worked for two years as CTO at Elo7 – the biggest crafts marketplace in Brazil. Experienced working in different programming languages such as Elixir, Ruby, JavaScript and Java, Daniel helped many startups as venture advisor at Monashees Capital and other accelerator programs in Brazil. He is also PhD in Computer Science at University of São Paulo – IME-USP. His PhD research is about Software Startups Ecosystems and Entrepreneurship. Daniel mastered in Computer Science in University of São Paulo in 2009, with the Thesis Patterns for Introducing New Ideas in the Software Industry. Daniel is a Cloud Computing GDE (Google Developer Expert). Daniel started developing software in Brazil when he was 10, on his TK-3000 Basic 2MB RAM computer. He worked as a consultant and software developer in many companies. In 2001, he worked for an Internet startup in Italy. In 2006 he joined Locaweb, the biggest web hosting company in Brazil and worked there for 5 years as developer and tech lead in infrastructure team. Daniel is an active member in the agile and software development communities, speaker in many conferences such as Elixir Brasil, QCON, Agile Brasil, TDC, DevCamp, Agile Trends and others. Studying other Arts beside software development, like Theatre, musical instruments and compositions, dance and writing, he acted in five musical plays and has a poetry book published. Daniel is a Vipassana meditation student and is very interested in topics related to human consciousness.
Updated on September 17, 2022Comments
-
Daniel Cukier over 1 year
I have a background process running at 100% CPU on Mac OS X. All other applications are very slow because of it.
I'd like to set this process to take no more than 50% so that my applications can run better. How can I do this?
-
Daniel Cukier over 14 yearsAnd how can I do with an already running process? It's running for 2 hours and I don't want to start it again and loose my 2 hours of processing
-
Hannah over 11 yearsBeNicer and Process Wizard are both PowerPC apps and won't run on recent versions of OSX
-
nyxee about 7 yearsAdditionally, using
renice -20
gives a process the highest possible priority, for example when compiling a big program like octave.renice 20
gives a process the lowest priority. -
ylluminate about 7 yearsIs Freezer still working on newer OS releases?
-
JacopKane over 5 yearsplease check my answer for another alternative, AppPolice
-
Ky. about 4 yearsI think it's worth noting that BeNicer and Process Wizard only run on PowerPC processors, so they won't run at all on any Mac which Apple currently supports. Freezer works, but for me it seems to only work for apps that show up in the Dock, not Menu Bar apps like Backup and Sync from Google