The nice
command is used with its -n
option, along with an argument in the range of -20
to 19
, in order from highest to lowest priority (the lower the number, the higher the priority). For example, to run the gkrellm
client with a low priority, use the nice
command like this:
$ nice -n 12 gkrellm &
The nice
command is typically used for disk- or CPU-intensive tasks that might be obtrusive or cause system slowdown. The renice
command can be used to reset the priority of running processes or control the priority and scheduling of all processes owned by a user. Regular users can only numerically increase process priorities (that is, make tasks less important) with this command, but the root operator can use the full nice
range of scheduling (- 20
to 19
).
System administrators can also use the time
command to get an idea of how much time and what proportion of a system's resources are required for a task, such as a shell script. (Here, time
is used to measure the duration of elapsed time; the command that deals with civil and sidereal time is the date
command.) This command is used with the name of another command (or script) as an argument like this:
# time -p find / -name core -print
/dev/core
/proc/sys/net/core
real 1.20
user 0.14
sys 0.71
Output of the command displays the time from start to finish, along with the user and system time required. Other factors you can query include memory, CPU use, and file system input/output (I/O) statistics. See the time
command's man page for more details.
Nearly all graphical process-monitoring tools include some form of process control or management. Many of the early tools ported to Linux were clones of legacy UNIX utilities. One familiar monitoring (and control) program is top
. Based on the ps
command, the top
command provides a text-based display of constantly updated console-based output showing the most CPU-intensive processes currently running. It can be started like this:
# top
After you press Enter, you see a display as shown in Figure 12.1. The top
command has a few interactive commands: Pressing h
displays the help screen; pressing k
prompts you to enter the PID of a process to kill; pressing n
prompts you to enter the PID of a process to change its nice
value. The top
man page describes other commands and includes a detailed description of what all the columns of information top
can display actually represent; have a look at top's well-written man
page.
FIGURE 12.1 The top
command can be used to monitor and control processes. Here, we are prompted to renice
a process.
The top
command displays quite a bit of information about your system. Processes can be sorted by PID, age, CPU or memory use, time, or user. This command also provides process management, and system administrators can use its k
and r
keypress commands to kill and reschedule running tasks, respectively.
The top
command uses a fair amount of memory, so you might want to be judicious in its use and not leave it running all the time. When you've finished with it, simply press q
to quit top
.
Displaying Free and Used Memory with free
Although top includes some memory information, the free utility displays the amount of free and used memory in the system in kilobytes (the -m switch displays in megabytes). On one system, the output looks like this:
# free
total used free shared buffers cached
Mem: 1025368 995860 29508 0 56472 551464
-/+ buffers/cache: 387924 637444
Swap: 2031608 0 2031608
Swap: 433712 0 433712
This output describes a machine with 1GB of RAM memory and a swap partition of 2GB. Note that no swap is being used, although the machine is heavily loaded. Linux is very good at memory management and "grabs" all the memory it can in anticipation of future work.
TIP
A useful trick is to employ the watch
command; it repeatedly reruns a command every 2 seconds by default. If you use
# watch free
you can see the output of the free command updated every 2 seconds.
Another useful system-monitoring tool is vmstat
( virtual memory statistics ). This command reports on processes, memory, I/O, and CPU, typically providing an average since the last reboot; or you can make it report use for a current period by telling it the time interval in seconds and the number of iterations you desire, as follows:
# vmstat 5 10
The preceding command runs vmstat
every 5 seconds for 10 iterations.
Use the uptime
command to see how long it has been since the last reboot and to get an idea of what the load average has been; higher numbers mean higher loads.
Disk quotas are a way to restrict the use of disk space either by user or by groups. Although rarely — if ever — used on a local or standalone workstation, quotas are definitely a way of life at the enterprise level of computing. Use limits on disk space not only conserve resources, but also provide a measure of operational safety by limiting the amount of disk space any user can consume.
Disk quotas are more fully covered in Chapter 10, "Managing Users."
Graphical Process and System Management Tools
The GNOME and KDE desktop environments offer a rich set of network and system- monitoring tools. Graphical interface elements, such as menus and buttons, and graphical output, including metering and real-time load charts, make these tools easy to use. These clients, which require an active X session and (in some cases) root permission, are included with Fedora.
If you view the graphical tools locally while they are being run on a server, you must have X properly installed and configured on your local machine. Although some tools can be used to remotely monitor systems or locally mounted remote file systems, you have to properly configure pertinent X11 environment variables, such as $DISPLAY
, to use the software or use the ssh
client's - X
option when connecting to the remote host.
Fedora no longer includes the xosview
client, which provided load, CPU, memory and swap use, disk I/O use and activity, page-swapping information, network activity, I/O activity, I/O rates, serial port status, and if APM is enabled, the battery level (such as for a laptop). However, a great replacement is GKrellM, which provides a much neater interface and a host of additional plug-ins. You have to use this command to retrieve GKrellM:
# yum install gkrellm
After you have installed GKrellM, you can find it under Applications, System Tools. Figure 12.2 shows GKrellM.
FIGURE 12.2 GKrellM allows you to monitor most system processes on Fedora.
Читать дальше