Nice
The nice
command allows you to run a process with a higher or lower priority than the default, which can affect how much CPU time it gets relative to other processes running on the system. This can be useful for both interactive users who want to prioritize their own tasks and system administrators trying to manage resource usage.
Basic Usage
The basic syntax of nice
is:
bash
nice [option] command
Where command
is the process you want to run with a different priority. The [option]
can be either -n
or +n
, where n
is an integer value that represents the nice level, ranging from -20 (highest priority) to 19 (lowest priority). If you omit this option, nice
defaults to running the command with a priority of zero.
Example
To run a process with higher priority:
bash
nice -10 firefox &
In this case, Firefox will get more CPU time relative to other processes.
Special Hack
One advanced use of nice
is in conjunction with the renice
command. While nice
affects the priority of a process at runtime, renice
allows you to change the priority of running or even suspended processes. This can be especially useful when trying to manage resource usage on systems where processes are already running.
bash
renice -n 10 -p 12345 &
Here, we’re changing the nice level (priority) of a process with PID 12345
to a lower value (-10
), which would give it less CPU time and could help prevent it from consuming too much system resource.
Level of Experience
This command is most relevant for users who want fine-grained control over process priorities, including system administrators trying to manage workload and optimize performance. It’s also useful for power users looking to prioritize their own processes or scripts running in the background.
Beginners should be aware that nice
and its cousin renice
offer a level of process management flexibility but can complicate resource allocation. Intermediate users will likely find them useful as they delve deeper into system optimization and troubleshooting, while professionals will appreciate the granular control these tools provide over system resources.