Change Process Priority with nice and renice in Linux
Learn how Linux nice and renice values affect CPU scheduling, how to start or modify processes, check permissions, verify NI values, and troubleshoot priority changes.
Linux can adjust a process's relative preference for CPU time with a nice value. This lesson shows how to start a command with nice, change an existing process with renice, verify the result, and avoid common permission and scheduling mistakes.
A process is an executing program managed by the operating system. Each process has a numeric process identifier, or PID. The CPU scheduler is the kernel component that chooses which runnable task receives CPU time.
What Process Priority Means
Process priority is one input the scheduler uses when allocating CPU time among runnable processes. A runnable process is ready to execute but is waiting for a CPU. Adjusting its nice value changes its relative scheduling preference when it competes with other runnable work.
A nice value does not guarantee that a program will finish by a particular time, and it does not reserve CPU resources. It is most noticeable during CPU contention, which means multiple workloads are competing for limited processor time.
Nice values are also not the same as:
- I/O priority: preference for disk or other input/output operations, which can be managed separately with tools such as
ionice. - Memory limits: restrictions on RAM or swap usage, commonly handled with resource controls.
- Real-time scheduling policies: special scheduling policies managed with tools such as
chrt. Nice values do not turn an ordinary process into a real-time process.
Nice Values and Their Range
A nice value is a scheduler-related value conventionally ranging from -20 through 19. An ordinary newly started process normally begins at 0.
The numbering is inverse to what beginners often expect:
- A lower numeric value means a higher relative CPU scheduling preference. For example,
-10is favored more than5. - A higher numeric value means a lower relative CPU scheduling preference.
- A positive value makes a process more “nice” to competing work by yielding relatively more CPU opportunity.
| Nice value or range | Relative CPU scheduling preference | Typical permission requirement | Appropriate use |
|---|---|---|---|
| -20 to -1 | Higher priority | Normally privileged | Only for justified workloads that need extra CPU preference |
| 0 | Default priority | Normally allowed | Ordinary processes |
| 1 to 19 | Lower priority | Normally allowed for the user's own processes | Background, batch, or non-urgent work |
These values express relative preference, not a promise of a fixed percentage of CPU time.
Permissions and Ownership
Users can normally adjust only processes they own. An unprivileged user can generally increase the numeric nice value, lowering the priority of that user's process.
Assigning a negative nice value, or otherwise moving a process toward higher priority, normally requires elevated privilege. On Linux this commonly means using sudo, subject to resource limits and applicable capabilities. Even changing a process back toward a higher priority can be restricted.
This restriction protects the system: if every user could arbitrarily increase priority, one user's workload could unfairly dominate CPU time and make interactive work or critical services unresponsive.
Start a Command with nice
nice launches a new program with an adjusted niceness. Its standard option form is:
nice -n adjustment command [arguments...]On common Linux implementations, -n specifies an adjustment relative to the invoking shell's inherited nice value. If the shell has the normal value of 0, the following command starts with nice value 15:
nice -n 15 vimThis starts vim with lower relative CPU priority. A normal user can usually do this for a process they start. Check the resulting value rather than assuming it, especially if the shell already inherited a nonzero nice value.
To request a higher relative priority, use a negative adjustment with appropriate privilege:
sudo nice -n -15 vimNegative nice values indicate higher relative scheduling priority. Use them carefully: a CPU-intensive high-priority process can reduce responsiveness for other workloads. The request must also fit the system's configured limits.
Verify a Newly Started Command
After launch, identify the process and inspect its nice value:
pgrep -a vim
ps -o pid,user,ni,pri,comm -p PIDReplace PID with the identifier returned by pgrep. The NI column shows the nice value; PRI is another displayed priority field and should not be confused with the nice value.
Change an Existing Process with renice
renice changes the niceness of a process that is already running. The basic target is a PID, which is the numeric identifier assigned to that process.
renice -n 15 -p 14475This sets the nice value of process 14475 to 15. It changes an existing process rather than launching a new one. The process owner can normally make the process less favored by increasing its numeric nice value.
Raising priority requires authorization:
sudo renice -n -15 -p 14475Use elevated access only when authorized and operationally justified. Depending on the implementation and options, renice can also target process groups or users, not only individual process IDs.
Find and Validate a Process
Always identify and validate a target before using renice. A PID can be reused after a process exits, so an old PID may later refer to a different program.
| Command | Purpose | Useful fields or output | Safety note |
|---|---|---|---|
pgrep -a vim | Find matching processes and show command lines | Candidate PIDs and full command text | Confirm the command is the intended one |
ps -o pid,user,ni,pri,comm -p 14475 | Inspect a specific process | PID, owner, nice value, displayed priority, and command | Check owner and command immediately before changing priority |
top or htop | Observe processes interactively | NI field, CPU use, and process behavior | Use the displayed command and user to validate identity |
pgrep -a vim
ps -o pid,user,ni,pri,comm -p 14475In top or htop, look for the NI column. It shows the process's nice value while CPU usage and system responsiveness help you judge the practical effect.
nice and renice Compared
| Utility | When to use it | Target | Example | Permission considerations |
|---|---|---|---|---|
nice | When launching a new command | A new program | nice -n 15 vim | Positive adjustments are normally permitted; negative adjustments usually need privilege |
renice | When modifying a running process | A PID, process group, or user target | renice -n 15 -p 14475 | Ownership and privilege rules apply; priority increases are restricted |
Practical Examples
Lower the Impact of a Batch Job
For a non-urgent compression job, start it with a modestly lower scheduling preference:
nice -n 10 tar -czf backup.tar.gz important-directory/This can reduce competition with interactive work when the system is busy. It is not a replacement for backup planning, I/O controls, memory limits, or other resource management.
Change a Running Workload
After validating the process identity and owner, lower the priority of the process with PID 14475:
renice -n 15 -p 14475Verify the change:
ps -o pid,user,ni,pri,comm -p 14475Practical Limitations and Scheduler Behavior
- Nice values matter most when runnable processes compete for CPU. On an idle system, changing niceness may produce little visible difference.
- A process blocked on disk, a network request, a lock, or another resource will not become faster merely because its nice value changes.
- Multithreaded applications may have several schedulable tasks, so changing one process may not produce the expected result for every thread.
- Containers, cgroups, CPU affinity, service-manager settings, and system load can constrain observed CPU behavior.
- Start with modest changes. Avoid unnecessarily high priority for long-running workloads.
Safe Administrative Workflow
- Identify the workload and determine whether CPU contention is actually the problem.
- Find the target with
pgrep,ps,top, orhtop. - Validate the PID, command, and process owner immediately before making a change.
- Apply a modest nice or renice value using the least privilege necessary.
- Verify the new
NIvalue withps,top, orhtop. - Monitor CPU behavior and system responsiveness.
- Revert or adjust the setting if interactive work or critical services are adversely affected.
Troubleshooting
Operation Not Permitted
This usually means the requested negative nice value requires privilege, the target belongs to another user, or a resource limit or system policy blocks the change.
- Confirm ownership with
ps. - Use a higher numeric nice value if your goal is to lower priority.
- Use
sudoonly when administrative authorization is appropriate. - Review applicable limits and service policies if authorized access still fails.
The Process Does Not Become Noticeably Faster
There may be little CPU contention, or the process may be waiting on disk, network, locks, or another dependency. CPU affinity, cgroups, container limits, and service settings may also constrain it.
Check CPU use and process state with top, htop, or ps. Identify the actual bottleneck before applying a more aggressive priority change.
renice Targets the Wrong Workload or Finds No Process
The PID may be incorrect, the process may have exited, or the PID may have been reused. Run pgrep and ps immediately before changing priority, and validate the PID, owner, and command together. For short-lived jobs, launch them with nice instead of trying to find them later.
System Responsiveness Gets Worse
A CPU-intensive workload may have been given too much scheduling preference, or multiple high-priority processes may now compete with interactive work.
sudo renice -n 5 -p 14475Increasing the numeric value reduces the process's relative priority. Avoid negative nice values unless there is a clear operational need, and monitor the system after every change.
Exam-Relevant Notes
- The conventional nice range is
-20through19. - Lower numeric nice values mean higher relative CPU scheduling preference.
- A normal process usually starts at nice value
0. nicestarts a new command;renicechanges an existing process.- A PID identifies a running process, but PIDs can be reused.
- Unprivileged users can generally lower the priority of their own processes, while priority increases normally require privilege.
- Nice changes influence CPU scheduling preference; they do not guarantee completion time or control I/O, memory, or real-time scheduling.
For broader process-management commands, see Linux and related shell command material such as Show the Full Path of Shell Commands.