Quick take: The nice command starts a process with a chosen priority (niceness), and renice changes a running one. Niceness ranges from -20 (highest priority) to 19 (lowest). nice -n 10 ./job.sh runs a job at low priority so it does not hog the CPU.
Introduction
Linux shares CPU time among processes by priority, and the nice and renice commands let you influence that. Niceness runs from -20 (most aggressive, highest priority) to 19 (most generous, lowest priority) — a “nicer” process yields more CPU to others. Use them to keep a heavy background job from slowing down interactive work.
Syntax
The basic syntax of the nice and renice command is:
nice -n VALUE COMMAND
renice VALUE -p PIDCommon Options and Parameters
The most useful options and parameters for the nice and renice command:
| Option | Description |
|---|---|
| nice -n N CMD | Start CMD with niceness N (default 10 if no value). |
| renice N -p PID | Change the niceness of a running process. |
| renice N -u USER | Change niceness for all of a user's processes. |
| renice N -g GROUP | Change niceness for a process group. |
| -20 to 19 | Range: -20 highest priority, 19 lowest. |
Practical Examples
Real nice and renice commands you can run today:
# Run a job at low priority
nice -n 15 ./backup.sh
# Run at high priority (needs root)
sudo nice -n -5 ./critical.sh
# Lower a running process's priority
renice 10 -p 4821
# Raise a running process's priority (root)
sudo renice -5 -p 4821
# Renice all of a user's processes
sudo renice 10 -u batchuser
# Check a process's niceness (NI column)
topTips and Best Practices
- Only root can assign negative niceness (higher priority); regular users can only make processes nicer (lower priority).
- Use a high niceness like
nice -n 19for backups, builds, and batch jobs so they yield to interactive work. - For disk-heavy jobs, also consider
ionice, which sets I/O priority — CPU niceness alone will not help if the bottleneck is the disk.
Final Thoughts
nice and renice let you balance CPU fairly by adjusting process priority — lowering a heavy job's priority so interactive work stays responsive, or (as root) raising a critical one. Remember the range runs -20 to 19 and that only root can raise priority. For I/O-bound work, pair them with ionice to control disk priority too.
FAQ: nice and renice Command in Linux
What does the nice command do?+
nice starts a process with a chosen scheduling priority, called niceness. A higher niceness (up to 19) means the process yields more CPU to others; a lower value (down to -20) gives it more priority.
How do I change the priority of a running process?+
Use renice with the new value and the PID: renice 10 -p 4821 lowers its priority. Raising priority (negative values) requires root.
What is the range of niceness values?+
Niceness ranges from -20 (highest priority, most CPU) to 19 (lowest priority, most generous). The default for a normal process is 0.
Why can't I set a negative niceness?+
Assigning higher priority (negative niceness) can starve other processes, so only root may do it. Regular users can only increase niceness, making their processes lower priority.
What is the difference between nice and ionice?+
nice controls CPU scheduling priority, while ionice controls disk I/O priority. For a job that is slow because of heavy disk access, ionice helps where nice alone will not.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support