Process Priority

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hello Cybrarians and welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gills.
00:00
In today's lesson, we're going to be
00:00
talking about process priority.
00:00
Upon completion of today's lesson,
00:00
you're going to be able to understand
00:00
the importance of process priority,
00:00
we'll also talk about the range of
00:00
Linux process priorities and see how we can
00:00
use the nice and renice commands to
00:00
set and change priorities respectively.
00:00
Linux is a multitasking OS and
00:00
>> it cycles CPU time between
00:00
>> different processes and really makes
00:00
them appear as if they're running concurrently.
00:00
We've spoken about this a little bit previously
00:00
about swap and context switching.
00:00
Processes that are sleeping is swapped out.
00:00
This is part of what we see when we're working with a
00:00
multi-tasking that's performed by
00:00
the Linux operating system.
00:00
To keep up the appearance of process concurrence,
00:00
Linux is going to try and give
00:00
equal CPU time to each and every process,
00:00
but what if we want to give a
00:00
certain process more importance?
00:00
While the priority level for a
00:00
>> process is what determines
00:00
>> the importance of that process relative
00:00
to all the other processes
00:00
that are running on the system.
00:00
Now, the better priority,
00:00
the more CPU time the process receives.
00:00
The process priority ranges a little bit wacky.
00:00
The 0 is the priority of most processes.
00:00
That is the default level that
00:00
most processes gives process priority
00:00
0, or dead in the middle.
00:00
But the priority of a process is determined on
00:00
a plus 19 to negative 20 scale.
00:00
The lower the number,
00:00
the better the priority is,
00:00
the higher the number,
00:00
the lower the priority is.
00:00
You can see the lowest priority is plus 19,
00:00
the highest number, and
00:00
the highest priority is negative 20, the lowest number.
00:00
Now, process priority can be set
00:00
>> using the nice command,
00:00
>> but only when starting a process.
00:00
You can specify a process priority
00:00
when you're starting a process by using nice-n,
00:00
the process level that you want
00:00
>> to use, and the command.
00:00
>> Now, if you're starting a process with nice,
00:00
but you don't specify the level,
00:00
it's going to give it priority level 10.
00:00
That's the nice default priority level 10,
00:00
not 0, it gives
00:00
a 10 because again, you're trying to be nice.
00:00
That's the purpose of the command.
00:00
You want to give a little bit of processing
00:00
back everything else in the system.
00:00
Users can start a process with
00:00
a lower priority or a higher number.
00:00
They're going to be lower priority,
00:00
higher numbers, 1-19,
00:00
19 being the lowest priority.
00:00
But privileged users or root can
00:00
start a process with a higher priority,
00:00
or a lower number,
00:00
negative 1 and negative 20.
00:00
Remember, negative 20 is
00:00
the highest priority and the lowest number.
00:00
We can see the niceness of the process,
00:00
but we're using something like top, we can see,
00:00
for example, the NI column here in top,
00:00
then indicates the niceness of certain processes.
00:00
Now, the process priority can be
00:00
changed using the renice command,
00:00
an ordinary user can increase the nice value.
00:00
In other words, lower the priority with renice.
00:00
They can renice and then use positive nice values,
00:00
so 1-19, so lower priority,
00:00
and then specify the process ID they want to change,
00:00
and a privileged or a root user,
00:00
can decrease the nice value and
00:00
therefore increase the priority with renice.
00:00
Sudo renice and then provide a nice value,
00:00
negative 1 all the
00:00
way up to negative 20 and then provide the process ID.
00:00
Nice value can also be seen with ps,
00:00
just like we saw with top,
00:00
but you have to specify columns by using p-s dash eo.
00:00
For example, you see ps -eo and then user,
00:00
pid, nice, cpu,
00:00
mem, so on and so forth.
00:00
You specify the columns that you want to see,
00:00
and then they get displayed like we
00:00
see over on the right-hand side.
00:00
With that, in this lesson, we cover the importance of
00:00
process priority and we talked about
00:00
the range of process priorities.
00:00
For example, plus 19 is going to
00:00
>> be the lowest priority.
00:00
>> Zero is going to be the default priority.
00:00
A priority of 10 is the default priority for nice,
00:00
we don't specify a level where we're starting nice,
00:00
and negative 20 is going to be
00:00
the highest priority than any process can have.
00:00
We can use the nice command to set process priority,
00:00
and we can use the renice command to
00:00
change process priority that's been set.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next