Linux Process Prioritization (Short Practical Guide)
When a system is busy, process priority helps decide what gets CPU and I/O time first.
1) CPU priority with nice
nice sets a process niceness from -20 (highest priority) to 19 (lowest priority).
Start a low-priority background job:
nice -n 10 tar -czf backup.tar.gz /data
Start a higher-priority job (usually requires root for negative values):
sudo nice -n -5 ./latency_sensitive_app
Check NI (niceness) and PRI:
ps -eo pid,comm,ni,pri,pcpu --sort=-pcpu | head
2) Change running process priority with renice
Raise niceness (less CPU share):
renice 10 -p 1234
Lower niceness (more CPU share, root required):
sudo renice -5 -p 1234
By user:
sudo renice 5 -u www-data
3) I/O priority with ionice
Useful when disk-heavy tasks make the system feel slow.
Run backup with low I/O priority:
ionice -c3 nice -n 15 rsync -a /src /dst
Set best-effort class with level 7 (lowest in class):
sudo ionice -c2 -n7 -p 1234
4) Real-time scheduling with chrt (advanced)
For strict latency needs (audio/control loops), use carefully.
Start with FIFO policy and priority 50:
sudo chrt -f 50 ./realtime_worker
Inspect scheduling policy and priority:
chrt -p 1234
Set an existing process:
sudo chrt -r -p 30 1234
5) Pin process to specific CPU cores
Can reduce jitter by limiting where a process runs.
taskset -c 2,3 ./app
Set affinity on running process:
taskset -cp 2,3 1234
6) Persist settings with systemd
For services, set priority in the unit file instead of manual commands.
[Service]
Nice=-5
IOSchedulingClass=best-effort
IOSchedulingPriority=2
CPUAffinity=2 3
Then reload and restart:
sudo systemctl daemon-reload
sudo systemctl restart your-service
Quick recommendations
- Use
nice/renicefirst for most cases. - Add
ionicefor backup, sync, compression, and indexing jobs. - Use
chrtonly when latency is critical and tested. - Monitor impact with
top,htop,pidstat, andiostat.
Small tuning usually beats aggressive tuning. Start conservative, measure, then adjust.