-->

Previous | Table of Contents | Next

Page 348

have not been used for a while so that when the memory is needed, it is available. The system will not have to wait for the memory to be swapped out.

Momma Always Said to Be Nice!

I grew up with two older brothers and one younger one. There were many times when Momma said to one or more of us to be nice! Sometimes the same is true for our processes. The renice command is used to alter the priority of running processes.

By default in Red Hat Linux, the nice value is 0. The range of this is _20 to 20. The lower the value, the faster the process runs. The following example shows how to display the nice value by using the nice command. My shell is running at the default value of 0. To check this another way, I issue the ps -l command. The NI column shows the nice value:


shell:/home/dpitts$ nice

0

shell:/home/dpitts$ ps -l

 FLAGS   UID   PID  PPID PRI  NI   SIZE   RSS WCHAN       STA TTY TIME COMMAND

   100   759  3138  3137   0   0   1172   636 force_sig   S   p0  0:00 -bash

100000   759  3307  3138  12   0    956   336             R   p0  0:00 ps -l

I change the nice value by using the renice command. The syntax of the command is as follows:


renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]

In the following example, the shell's nice value is changed to a value of 5. This means that any process with a lower value will have priority on the system.


shell:/home/dpitts$ renice 5 3138

3138: old priority 0, new priority 5

shell:/home/dpitts$ nice

5

shell:/home/dpitts$ ps -l

 FLAGS   UID   PID  PPID PRI  NI   SIZE   RSS WCHAN       STA TTY TIME COMMAND

   100   759  3138  3137   5   5   1172   636 force_sig   S N p0  0:00 -bash

100000   759  3319  3138  14   5    968   368             R N p0  0:00 ps -l

The owner of the process (and root) has the ability to change the nice value to a higher value. Unfortunately, the reverse is not also true:


shell:/home/dpitts$ renice -5 3138

renice: 3138: setpriority: Permission denied

Only root has the capability to lower a nice value. This means that even though I set my shell to a nice value of 5, I cannot lower it even to the default value.

The renice command is a wonderful way of increasing the apparent speed of the system for certain processes. This is a trade-off, though, because the processes that are raised will now run slower.

Page 349

Summary

Computers slow down significantly when they run out of memory. Also, if they try to do too much at one time, they seem slow. As a system administrator, your job is to determine whether the system is really slow or just seems slow. The difference is significant. If the system seems slow, the problem is usually a matter of adjusting the times certain processes are run. Using cron and at helps to schedule certain activities when the system is otherwise idle.

If the system is really slow, that is, waiting on processes all the time, with consistent IO waits, then it is time to invest in more equipment. The other option is to just live with it. (Get your users to buy off on that one!) As system administrator, your job is to keep performance at an acceptable level. With tools such as vmstat and top, this task is much simpler.

Sacrificing speed in certain processes is another way of increasing the apparent speed of other processes. The basic concept is that each process gets a certain piece of the processing pie. Certain processes can have a smaller, or root can give them a larger, piece of the processing pie. The amount of processing that can be completed never changes. The change is in how much processing time each process gets. Mainframes call this cycles. The lower your nice value, the more cycles you get each time the processor comes to do your work.

Page 350

Previous | Table of Contents | Next