The nice command in Linux is used to start a process with a specified priority. The priority range is from -20 (highest priority) to 19 (lowest priority). The default priority is 0.
- High value (e.g., 19): The process is given lower priority, allowing other processes to have more CPU time.
- Low value (e.g., -20): The process is given higher priority and gets more CPU time.
The renice command is used to change the priority of an already running process. It takes a PID and the new priority value as arguments.
Here are examples for the nice and renice commands:
- Using
niceto start a process with lower priority:
nice -n 10 command_name
This starts command_name with a priority of 10, meaning it will run with lower priority.
- Using
niceto start a process with higher priority:
nice -n -10 command_name
This starts command_name with a priority of -10, giving it higher priority.
- Using
reniceto change the priority of an existing process (PID 1234):
renice -n 5 -p 1234
This increases the priority of the process with PID 1234, lowering its CPU time allocation.
- Using
reniceto increase the priority (higher value means more CPU time):
renice -n -5 -p 1234
This gives the process with PID 1234 higher priority (less nice).