Altering Process
Priorities
Mike Bunch
LINUX TRAINING ARCHITECT
ALTERING PROCESS PRIORITIES
Lesson Objectives and Overview
Lesson Objective
Review the nice (niceness) values for a process and demonstrate how to use nice, renice, top and htop
utilities to view and modify the niceness factor of actively running processes.
Lesson Notes
What is niceness?
In simple terms, niceness is a numeric scale used to describe the relative priority of a process.
What is a niceness scale?
A 40 value range, with -20 being the highest priority value and 19 being the lowest priority value.
Notes about the niceness value:
The default value is 0 for most processes.
A child process will inherit its niceness value from the parent process.
ALTERING PROCESS PRIORITIES
Command Examples from the Lesson
# View process nice value for all processes, sorting by nice value:
ps -eo pid,comm,nice,cls --sort=-nice
top -o NI
htop
-- click on the NI column to sort
# View process nice value for specific process name:
ps -eo pid,comm,nice,cls | grep -v grep | grep -e PID -e <NAME>
# View process nice value for specific PID:
ps -eo pid,comm,nice,cls | grep -v grep | grep -e PID -e <PID>
ALTERING PROCESS PRIORITIES
Command Examples from the Lesson
# Start a bash process with a specific nice value:
nice -n 15 bash
# Change the process nice value for a running process:
sudo renice -n 5 <PID>
-- Elevated privileges are necessary to reduce the value.
# Change the process nice value for a running process using top:
sudo top
-- type a lowercase 'r', enter the PID, enter the new value
# Change the process nice value for a running process using htop:
sudo htop
-- locate the process, click the 'Nice -' or 'Nice +' buttons to update
ALTERING PROCESS PRIORITIES
Lesson Summary
Lesson Review
Discussed what niceness means and the niceness scale.
Talked about the default value and niceness inheritance.
Used ps, top and htop to view niceness values processes.
Used nice to start a process with a specific value, renice to change the value for a running process.
Used top and htop to change the value for a running process.