nice - macOS
Overview
The nice
command in macOS allows users to adjust the priority of a command or process, influencing how quickly the system allocates resources to it. It is commonly used to give higher or lower priority to specific tasks, ensuring a balanced resource distribution among multiple processes running concurrently.
Syntax
nice [-n increment] [-i increment] command [arguments]
Options/Flags
- -n increment: Adjust the nice level positively by increment. Higher values (up to 19) indicate lower priority, while lower values (down to -20) indicate higher priority. The default increment is 10.
- -i increment: Similar to -n, but adjusts the nice level inversely. Lower values indicate lower priority, while higher values indicate higher priority.
Examples
- To run
ls
with a higher priority (-5):
nice -n -5 ls
- To run
sleep 10
with a lower priority (15):
nice -n 15 sleep 10
- To increase the priority of the
top
process by 3:
nice -i 3 top
Common Issues
- Permission denied: Ensure you have sufficient user privileges to adjust process priorities (sudo may be required).
- Invalid increment: The increment must be between -20 and 19.
- No effect: Processes with very low priority (above 19) may not experience any noticeable performance changes.
Integration
nice
can be used in conjunction withrenice
, which allows for dynamic adjustment of process priorities while they are running.- It can be combined with
ps
to display the priority level of running processes. For example:
ps -e -o nice,command
Related Commands
ps
– Display process information.renice
– Change the priority of a running process.top
– Monitor system performance and running processes.