- [Narrator] Linux process priorities
are handled by a system called nice.
Nice levels go from -1 to -19 for privileged users.
The scale goes from 0 to 19 for nonprivileged users.
The default nice lever is zero.
When a process is started it has a default nice level.
The nice level is the number that reflects
how nice the process is to the CPU.
The nicer a process is to the CPU,
the less it interrupts it and the lower it's priority is.
Because the process is getting fewer resources
from the CPU, it also has lower priority.
This means other processes will get more CPU time
than it will.
If the nice level is less than zero
then it is less nice to the CPU
and demands more resources from it.
Thus having a higher priority for CPU time.
In summary, the higher the nice number,
the lower the CPU priority.
The lower the nice number, the higher the CPU priority.
Let's go to terminal to see how this works.
If we want to start a process
with a predetermined nice level,
we can start it with a nice command.
I'm going to open a second terminal
by going to file, open terminal
and drag it to the right border and then bump the font size.
I'm going to take my original terminal,
double click the title bar
and then drag it to the left border.
Now I can see both terminals.
In the right hand terminal, type in nice -2 top,
and hit enter.
In the left terminal,
type in ps -C top --format pid,nice,cmd
and hit enter.
Notice the nice level is positive 2
instead of -2.
The argument to set the nice level is hyphen,
followed by the numeric nice level.
Thus -2 equals 2.
Click on the right hand terminal
and press Q to quit top.
If you want to set a nice level of -2,
the option would be --2.
Also, only privileged users can set
negative nice levels, so we'll need to use sudos.
Type in sudo nice --2 top, and hit enter.
Type in your password and hit enter again.
Now, in the first terminal
bring your line back and hit enter.
Now you see that top is running with a nice level of -2.
The niceness of a process can also be changed
after the process is running, using the renice command.
We'll need our process ID number for the next command.
Type in sudo renice 5 and then the process ID
from the previous command.
In my case, it's 4772, then hit enter.
Type in your password and hit enter again.
We can verify our nice level by bringing back
our last ps line by hitting the up arrow key
and then hit enter again.
Note that we had to elevate privileges,
because the old level was -2.
To change to or from a negative level
we have to be a privileged user.