- In this video, we are going to explain what you
can do to manage process priority.
The thing is that every user process by default
is started with the same priority
And to adjust priorities, user can use the nice command
to start processes with an adjusted priority.
Non-privileged users can only run processes
with a lower priority.
Privileged users can increase
and decrease process priority.
And if you are going to use the nice command,
the priority that you will use reaches from -20,
which is the highest priority to positive 19,
which is the lowest priority.
If you want to adjust priorities for learning processes,
you can use renice,
but you can also use top to nice your processes.
Let me demonstrate.
All right, let's start with this nice command.
Nice - - help just to show you how it is used.
So we can see that nice is worked
with options and command and argument.
And the command is - n for the adjustment.
So - n adds the integer n to the niceness.
And if you don't do anything,
the integer that is added is the 10.
10 means that the process is becoming the least favorable,
in terms of priority, because it's a positive value.
You want it to have more attention,
give it an a negative value.
So if I use
nice - n - 10 dd if=/dev/zero of=/dev/null
So if I use nice - n - 10 on the dd command,
I am getting permission denied.
Does that make sense?
Yes, it does.
Because only user route can increase the priority.
So I need to do in order to do that.
So there we go.
And oops, I'm running it as a foreground process now.
I don't want to do that.
So control z and bg to continue running it
as a background process.
Now I'm going to run it once more this time
without the nice command.
And then we are going to monitor and see
if we see any differences.
And this one needs to be a background process as well.
Now, how can we best observe
the differences and similarities between processes?
By using top.
And what do we see?
We see something interesting.
And the interesting thing is that we have two processes,
and these two processes, these two nice processes,
are running with the same priority.
That's not what I expected, but it totally makes sense,
because if you press one in top, we can see
that this is a two CPU system and the dd process can
run on one CPU at the same time.
So it doesn't really matter
that one of these processes is a higher priority.
One of them is occupying one CPU,
and the other one is occupying the other CPU.
And you will notice
that all the other processes will be running
on the other CPU as well.
And that's the result
of this increased priority of this one dd process.
Now you will see the difference,
if we start one more dd process, there we go.
And let's get back to top once more
because what do we see now?
We see process with PID 6525,
which has a nice value of minus 10,
and which has a CPU priority of 95%.
And then we see the two other processes,
the dd processes with the normal nice value
and they are running with 47% CPU usage.
Here you see the CPU usage
and here we see the nice values.
So zero is not adjusted.
Minus 10 means we do have an adjusted nice value.
And all this adjusted nice value influences a priority.
By default user processes will learn with priority 20.
If you tweak the nice value, then this priority is changing.
Let me use r, r for renice, because from within top
you can change priorities as well.
I want to renice 6548.
Notice that I'm running top
at the moment as an ordinary user,
and I am allowed to renice my own processes
and I'm going to give it a priority 15.
And what do we see?
We see that process.
Oh, it's descending in the list.
We see that 6548 now as a priority 35,
nice value of 15, and it almost gets no CPU cycles anymore.
And that is how you can use nice
to adjust process priority in Linux.