[
174
]
At this point, we know how to re-prioritize our running processes with
renice
. Now,
let's take a look at starting a new process with a specific priority with
nice
. Consider
the following command:
nice -n 10 vim
Here, we're launching a new instance of
vim
, but with the priority set to a specific
value right from the start. If we want to change the priority of
vim
again later, we'll
need to use
renice
. As I mentioned earlier,
nice
is used to launch a new process with
a specific priority, and
renice
is for changing the priority of a pre-existing process. In
this example, we launched
vim
and set its nice value to
10
in one command.
Changing the priority of a text editor such as
vim
may seem like an odd choice for
a test case, and it is. But the
vim
editor is harmless, as the likelihood of us changing
the priority of it leading to a system halt is extremely minimal. There's no practical
reason I can think of where it would be useful to re-prioritize something like a text
editor. The takeaway, though, is that you
can
change the priority of the processes
running on your server. On a real server, you may have an important process that
runs and generates a report, and that report must be delivered on time. Or perhaps
you have a process that generates an export of data that a client needs to have in
order to make an on-time deliverable. So, if you think of the bigger picture, you can
replace
vim
with the name of a process that is actually important for you or your
organization.
You might be wondering what "nice" means in the context of the
nice
and
renice
commands. The "nice" number essentially refers to how nice a process is to other
users. The higher the nice value, the lower the priority. So, a value of 20 is nicer
than a value of 10. In that case, processes with a niceness of 20 are running at a
lower priority, and so are kinder to the other processes on the system. The niceness
can range from -20 to 19. A process with a nice value of -20 is the highest priority
possible, while 19 is the lowest priority it can have. The entire system is quite a bit
more complicated than this simple description. Although I refer to the nice value as
the priority, it actually isn't. The nice value is used to calculate the actual priority. But
for now, if we simplify the nice value to be representative of the priority, and the nice
value to equate to a lower priority, the higher the number gets, that's enough for now.
So far, we've been using the
nice
and
renice
commands along with the
-n
option to
set the nice values directly. It may be interesting to note though that you can simplify
the
renice
command and leave out the
-n
option:
renice 10 42467
Chapter 7
Do'stlaringiz bilan baham: |