renice [-n] priority [[-p] pid...] [[-g] pgrp...] [[-u] user...]
The renice command alters the scheduling priority of one or more running processes. Process priority determines how much CPU time a process receives relative to other processes. The kernel scheduler uses nice values (ranging from -20 to 19) to determine process priority, where lower values indicate higher priority and more CPU time allocation.
This is crucial for system administrators managing resource-intensive applications, ensuring
critical processes get adequate CPU time, or throttling background tasks to prevent system
performance degradation. Unlike the nice command which sets priority at process
launch, renice modifies the priority of already-running processes.
# First, identify the process
ps aux | grep "gcc"
# Output shows: user 12345 ... gcc -O3 large_project.c
# Increase priority by setting nice to -5 (higher priority)
sudo renice -n -5 -p 12345
12345 (process ID) old priority 0, new priority -5
The -n flag specifies the new nice value. A nice value of -5 gives this process significantly more CPU time than processes at the default nice value of 0.
# Check current priority
ps -o pid,ni,cmd -p 23456
# Output: PID NI CMD
# 23456 0 /bin/bash backup.sh
# Decrease priority by setting nice to 15
renice -n 15 -p 23456
23456 (process ID) old priority 0, new priority 15
With nice value 15, the backup process will receive less CPU time, allowing interactive applications to remain responsive. This is commonly used for batch processing jobs.
# View current processes for user 'dataanalyst'
ps -u dataanalyst -o pid,ni,cmd
# Lower priority for ALL processes owned by this user
sudo renice -n 10 -u dataanalyst
1001 (user ID) old priority 0, new priority 10
2341: old priority 0, new priority 10
2342: old priority 0, new priority 10
2343: old priority 5, new priority 10
...
This affects ALL processes for the user, including their shell session and any interactive applications. Use with caution.
# Identify process group ID (PGID)
ps -eo pid,pgid,ni,cmd | grep render
# Output shows multiple processes with PGID 5678
# Adjust priority for entire process group
sudo renice -n 5 -g 5678
5678 (process group ID) old priority 0, new priority 5
Process groups are typically created when a process forks children. All processes in the group share the same PGID, making it easy to manage them collectively.
# Check current priorities
ps -o pid,ni,cmd -p 1234,2345,3456
# Set all to nice value 8
sudo renice -n 8 -p 1234 -p 2345 -p 3456
# Shorter syntax without repeating -p flag
sudo renice -n 8 1234 2345 3456
1234 (process ID) old priority 0, new priority 8
2345 (process ID) old priority 5, new priority 8
3456 (process ID) old priority 0, new priority 8
You can specify multiple PIDs with or without repeating the -p flag. Both syntaxes are valid.
# Identify database process
pgrep -a postgres | grep "main process"
# Output: 4567 postgres: main process
# Set to maximum priority
sudo renice -n -20 -p 4567
# Verify the change
ps -o pid,ni,pri,cmd -p 4567
4567 (process ID) old priority 0, new priority -20
PID NI PRI CMD
4567 -20 60 postgres: main process
Use maximum priority (-20) sparingly and only for truly critical processes. A process with nice -20 can starve other processes of CPU time, potentially making the system unresponsive.
# Find the ffmpeg encoding process
ps aux | grep ffmpeg
# Output: user 8901 ... ffmpeg -i input.mp4 -c:v h264 output.mp4
# Set to very low priority (highest nice value)
renice -n 19 -p 8901
# Monitor CPU usage to verify reduced priority
top -p 8901
8901 (process ID) old priority 0, new priority 19
# In top output, you'll see the PR (priority) column reflects the change:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8901 user 39 19 892516 123456 4567 R 15.0 2.3 5:23.45 ffmpeg
With nice value 19, the process will only get CPU time when higher-priority processes are idle. Perfect for long-running background tasks that aren't time-sensitive.
# Check current nice value
CURRENT_NICE=$(ps -o ni= -p 5432)
echo "Current nice: $CURRENT_NICE"
# Calculate new nice value (increase by 5)
NEW_NICE=$((CURRENT_NICE + 5))
# Apply new nice value
renice -n $NEW_NICE -p 5432
# Alternative: Use renice increment (if supported on your system)
# Some implementations support: renice +5 -p 5432
Current nice: 3
5432 (process ID) old priority 3, new priority 8
The standard renice command sets absolute values, but you can script relative adjustments. Some Unix variants support the +/- syntax for relative adjustments (e.g., renice +5 -p PID).
# Check if monitoring daemon is responsive
pgrep -a nagios
# Output: 6789 /usr/sbin/nagios -d /etc/nagios/nagios.cfg
# Check current load and nice value
ps -o pid,ni,pcpu,pmem,cmd -p 6789
# Shows: 6789 0 0.1 0.5 /usr/sbin/nagios
# Temporarily boost priority to recover
sudo renice -n -10 -p 6789
# Give it 30 seconds, then check if it's responding
sleep 30
systemctl status nagios
# If recovered, return to normal priority
sudo renice -n 0 -p 6789
6789 (process ID) old priority 0, new priority -10
# After 30 seconds and status check:
● nagios.service - Nagios Core
Active: active (running)
6789 (process ID) old priority -10, new priority 0
This is an emergency technique. Don't leave critical services at abnormal priorities long-term. Investigate why the process was starved in the first place.
#!/bin/bash
# File: manage_backup_priority.sh
# Purpose: Adjust priority for all backup processes
# Configuration
BACKUP_USER="backup"
LOW_PRIORITY=15
NORMAL_PRIORITY=0
# Function to lower priority for backups
start_low_priority_backup() {
echo "Lowering priority for backup processes..."
sudo renice -n $LOW_PRIORITY -u $BACKUP_USER
echo "Backup processes now running at nice level $LOW_PRIORITY"
}
# Function to restore normal priority
restore_priority() {
echo "Restoring normal priority for backup processes..."
sudo renice -n $NORMAL_PRIORITY -u $BACKUP_USER
echo "Backup processes restored to nice level $NORMAL_PRIORITY"
}
# Monitor and report
report_status() {
echo "Current backup process priorities:"
ps -u $BACKUP_USER -o pid,ni,cmd --sort=-pcpu | head -10
}
# Main execution
case "$1" in
start)
start_low_priority_backup
;;
stop)
restore_priority
;;
status)
report_status
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 1
;;
esac
Lowering priority for backup processes...
1001 (user ID) old priority 0, new priority 15
Backup processes now running at nice level 15
# Output when running: ./manage_backup_priority.sh status
Current backup process priorities:
PID NI CMD
9012 15 rsync -av /data /backup
9013 15 tar czf backup.tar.gz /home
9014 15 mysqldump --all-databases
This script demonstrates production-ready priority management. Schedule it with cron to automatically lower backup priority during business hours and restore it during off-hours.
top, htop, or ps
to verify the change took effect and monitor CPU usage. The PR (priority) column in top shows
the calculated priority (20 + nice value).
sudo renice -n 5 -p $(pgrep firefox). This adjusts all Firefox processes at once.