nice and renice — Managing Process Priorities in Linux¶
Linux allows multiple processes to compete for CPU time. The nice and renice commands help control process scheduling priority, allowing administrators to favor important workloads while reducing the impact of less critical tasks. Proper use of process priorities improves system responsiveness and overall performance in production environments.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Understand process priority
- Learn nice values
- Start processes with custom priorities
- Change the priority of running processes
- Understand CPU scheduling
- Improve application performance
- Apply priority management in production
Prerequisites¶
Complete:
- Module 1 – Linux Fundamentals
- Module 2 – Linux Command Line Essentials
- Module 3 – Text Processing
- Module 4 – File Management and Permissions
- Module 5 – Users and Groups
- Module 6 Lessons 1–5
Why Learn nice?¶
Imagine a production server running:
- Database
- Web Server
- Backup Job
- Log Compression
- File Synchronization
The backup job suddenly consumes all available CPU.
Users begin experiencing slow application performance.
Should the backup receive the same CPU priority as the database?
No.
Linux allows us to assign different priorities.
What is Process Priority?¶
Linux schedules CPU time based on process priority.
Higher-priority processes generally receive CPU time before lower-priority processes when CPU resources are limited.
Priority can be adjusted using:
nicerenice
What is a Nice Value?¶
A nice value tells the Linux scheduler how "nice" a process should be to other processes.
A higher nice value means the process is more willing to yield CPU time.
A lower nice value means the process receives higher scheduling priority.
Nice Value Range¶
| Nice Value | Meaning |
|---|---|
| -20 | Highest priority |
| 0 | Default priority |
| 19 | Lowest priority |
Note
Regular users can usually increase the nice value (lower priority) for their own processes. Lowering the nice value (raising priority) generally requires administrative privileges.
View Nice Values¶
Display running processes.
Example:
Observe:
This represents the nice value.
Start a Process with a Nice Value¶
Default:
Lower priority:
Verify:
Highest User Priority¶
Administrator only.
This gives the process a higher scheduling priority.
Change Priority of a Running Process¶
Use:
Example:
Meaning:
Increase Priority¶
Example:
Requires administrative privileges.
Decrease Priority¶
Example:
Regular users can generally lower the priority of their own processes by increasing the nice value.
View Process Priority¶
Example:
CPU Scheduling Example¶
The scheduler generally favors higher-priority processes when CPU resources are constrained.
Common Commands¶
Start with default priority.
Start with custom priority.
Change priority.
View priority.
Display nice values.
Real Production Examples¶
Low-priority backup.
Database maintenance.
Log compression.
Long-running reports.
Production Perspective¶
Process priorities are useful for:
- Database maintenance
- Backup jobs
- Log processing
- File synchronization
- Batch processing
- CI/CD runners
- Data analytics
- Large file compression
They help ensure background workloads don't unnecessarily impact interactive users or critical services.
Hands-on Lab¶
Task 1¶
Start a low-priority process.
Task 2¶
Find its PID.
Task 3¶
Display nice values.
Task 4¶
Change the priority.
Replace PID with the process ID from the previous task.
Task 5¶
Verify the change.
Task 6¶
Display detailed process information.
Task 7¶
Start another process with the default priority.
Compare the nice values.
Task 8¶
Terminate the test processes.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
nice | Start a process with a custom priority | Batch jobs |
renice | Change a running process priority | Performance tuning |
ps -el | Display priorities | Monitoring |
ps -o pid,ni,comm | Display nice values | Troubleshooting |
Production Troubleshooting Scenario¶
Scenario
A nightly backup begins at midnight.
Users report:
- Slow application response
- High CPU utilization
Investigation:
Findings:
The backup process is running with the default priority.
Solution:
Lower its scheduling priority.
Result:
- Backup continues running.
- Business applications receive CPU time more quickly.
- Overall system responsiveness improves.
Best Practices¶
- Run non-critical batch jobs with higher nice values (lower priority).
- Keep critical services at the default priority unless tuning is necessary.
- Increase process priority only when justified.
- Monitor CPU utilization before changing priorities.
- Test priority changes in non-production environments.
Common Mistakes¶
❌ Assigning the highest priority to every application.
✅ This defeats the purpose of process prioritization.
❌ Using negative nice values without understanding their impact.
✅ High-priority processes can reduce CPU availability for other workloads.
❌ Assuming nice changes process memory usage.
✅ It only influences CPU scheduling priority.
Interview Questions¶
Beginner¶
- What is a nice value?
- What is the default nice value?
- Which command starts a process with a custom priority?
- Which command changes the priority of a running process?
Intermediate¶
- What is the valid range of nice values?
- Why do lower nice values result in higher priority?
- When would you use
reniceinstead ofnice? - How do you display a process's nice value?
Architect Level¶
- How would you prioritize workloads on a busy production server?
- Which workloads should typically run with lower priority?
- Why is process priority tuning important for enterprise Linux systems?
Summary¶
In this lesson, you learned:
- Process priorities
- Nice values
- The
nicecommand - The
renicecommand - CPU scheduling
- Priority management
- Production best practices
Linux process priorities help administrators balance competing workloads by controlling CPU scheduling. Proper use of nice and renice improves system responsiveness and ensures critical applications receive appropriate CPU resources.
Key Takeaways¶
- Nice values range from -20 (highest priority) to 19 (lowest priority).
- The default nice value is 0.
- Use
niceto start a process with a custom priority. - Use
reniceto modify the priority of a running process. - Lower-priority background jobs should typically have higher nice values.
- Use process priorities carefully to maintain system performance.
What's Next?¶
The kill Command — Terminating Processes in Linux
You'll explore:
- Terminating processes
- Finding Process IDs (PIDs)
- Graceful vs forceful termination
- Killing multiple processes
- Common termination signals
- Production troubleshooting
Understanding process termination is an essential skill for managing Linux systems safely and effectively.