Process Priorities
Linux uses a scheduling priority system to decide which process runs on the CPU when multiple processes are competing. By adjusting process priorities you can ensure interactive applications respond immediately while background batch jobs use only leftover CPU time. This is especially useful on servers running both user-facing applications and resource-intensive background tasks like backups, cron jobs, or compression.
How Linux prioritizes processes
Linux priority system:
Nice value: -20 (highest priority) to +19 (lowest priority)
Priority (PR): 20 + nice value = actual scheduling priority
Nice -20 → PR 0 (most CPU time when competing)
Nice 0 → PR 20 (default — equal with other normal processes)
Nice +19 → PR 39 (only gets CPU when nothing else wants it)
Lower PR number = higher scheduling priority
Real-time priorities: PR -100 to -1 (even higher than nice values, requires root)Setting priority with nice
# Start a command with a specific nice value
# Default nice value is 0
# Start a backup script with lowest priority (nice +19)
nice -n 19 tar -czf /backup/home.tar.gz /home/
# Start a process with higher priority (requires root for negative values)
sudo nice -n -5 /opt/myapp/server
# Check the nice value in ps output (NI column)
ps aux | grep "tar"
ps output showing nice value
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1234 8.5 0.2 45678 2345 pts/0 SN 14:00 0:30 tar -czf ...
# ↑
# N = nice value > 0 (lower priority)
Changing priority with renice
# Change nice value of a running process
sudo renice -n 10 -p 1234 # Set PID 1234 to nice +10
sudo renice +19 -p 1234 # Alternative syntax
# Change nice for all processes of a user (background batch user)
sudo renice +15 -u batchjobs
# Change nice for all processes in a process group
sudo renice +10 -g PGID
# Verify the change
ps -p 1234 -o pid,ni,comm
Verifying the priority change
PID NI COMMAND
1234 10 tar
📝 NOTE: Regular users can only set their processes to a LOWER priority (higher nice value, e.g., +1 to +19). Only root can set processes to a HIGHER priority (negative nice value). Once a process is set to a lower priority, a regular user cannot increase it back to normal without root privileges.
Real-time scheduling
# Real-time scheduling gives a process guaranteed CPU time
# Required for audio/video applications, certain database workloads
# Show scheduling policy of a process
chrt -p PID
# Set a process to real-time (SCHED_FIFO, priority 50)
# WARNING: Real-time processes can starve other processes including the OS
sudo chrt -f -p 50 PID
# Set to SCHED_RR (round-robin real-time)
sudo chrt -r -p 50 PID
# Reset to default (SCHED_OTHER) scheduling
sudo chrt -o -p 0 PID
⚠️ WARNING: A misconfigured real-time process with priority 99 (SCHED_FIFO) that enters an infinite loop will completely lock up the system — not even the kernel watchdog can interrupt it. Only set real-time scheduling if you understand the application's behavior. Leave at least 5% CPU for non-real-time processes via
/proc/sys/kernel/sched_rt_runtime_us.
When to use priority tuning
| Scenario | Solution |
|---|---|
| Backup job is slowing the server | nice -n 19 the backup, or renice +19 if already running |
| Log compression cron job using too much CPU | Wrap with nice -n 15 in the cron command |
| Web app response is slow during CI builds | renice +10 the CI build worker processes |
| Database is being starved by OS processes | renice -n -5 the database (requires root) |
# Practical: wrap your rsync backup with low priority
nice -n 19 ionice -c 3 rsync -av /home/ /backup/home/
# nice -n 19 = lowest CPU priority
# ionice -c 3 = idle I/O class (only uses I/O when nothing else wants it)
Conclusion
Use nice -n 19 to start batch jobs (backups, compression) at minimum CPU priority so they do not compete with user-facing services. Use renice to adjust priority of already-running processes. Combine nice with ionice -c 3 for batch jobs that do heavy I/O — the I/O idle class ensures background jobs only use disk bandwidth when no other process needs it. Leave real-time scheduling to specialized applications that actually require it.
FAQ
Is Process Priorities important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support