A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)

Many utilities report on one thing or another. The who, finger, ls, ps, and other utilities generate simple end-user reports. In some cases, these reports can help with system administration. This section describes utilities that generate more in-depth reports that can usually provide more assistance with system administration tasks. Linux has many other report utilities, including (from the sysstat package) sar (system activity report), iostat (input/output and CPU statistics), and mpstat (processor statistics); (from the net-tools package) netstat (network report); and (from the nfs-utils package) nfsstat (NFS statistics).

vmstat: Reports Virtual Memory Statistics

The vmstat utility (procps package) generates virtual memory information along with (limited) disk and CPU activity data. The following example shows virtual memory statistics in 3-second intervals for seven iterations (from the arguments 3 7). The first line covers the time since the system was last booted; the rest of the lines cover the period since the previous line.

$ vmstat 3 7 procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 2 0 684328 33924 219916 0 0 430 105 1052 134 2 4 86 8 0 2 0 654632 34160 248840 0 0 4897 7683 1142 237 0 5 0 95 0 3 0 623528 34224 279080 0 0 5056 8237 1094 178 0 4 0 95 0 2 0 603176 34576 298936 0 0 3416 141 1161 255 0 4 0 96 0 2 0 575912 34792 325616 0 0 4516 7267 1147 231 0 4 0 96 1 2 0 549032 35164 351464 0 0 4429 77 1120 210 0 4 0 96 0 2 0 523432 35448 376376 0 0 4173 6577 1135 234 0 4 0 95

The following list explains the column heads displayed by vmstat.

  • procs

    • r

    • b

Process information

Number of waiting, runnable processes

Number of blocked processes (in uninterruptable sleep)

  • memory

    • swpd

    • free

    • buff

    • cache

Memory information in kilobytes

Used virtual memory

Idle memory

Memory used as buffers

Memory used as cache

  • swap

    • si

    • so

System paging activity in kilobytes per second

Memory swapped in from disk

Memory swapped out to disk

  • io

    • bi

    • bo

System I/O activity in blocks per second

Blocks received from a block device

Blocks sent to a block device

  • system

    • in

    • cs

Values are per second

Interrupts (including the clock)

Context switches

  • cpu

    • us

    • sy

    • id

    • wa

Percentage of total CPU time spent in each of these states

User (nonkernel)

System (kernel)

Idle

Waiting for I/O

top: Lists Processes Using the Most Resources

The top utility is a useful supplement to ps. At its simplest, top displays system information at the top and the most CPU-intensive processes below the system information. The top utility updates itself periodically; type q to quit. Although you can use command line options, the interactive commands are often more helpful. Refer to Table 16-2 and to the top man page for more information.

$ top top - 21:30:26 up 18 min, 2 users, load average: 0.95, 0.30, 0.14 Tasks: 63 total, 4 running, 58 sleeping, 1 stopped, 0 zombie Cpu(s): 30.9% us, 22.9% sy, 0.0% ni, 0.0% id, 45.2% wa, 1.0% hi, 0.0%si Mem: 1036820k total, 1032276k used, 4544k free, 40908k buffers Swap: 2048276k total, 0k used, 2048276k free, 846744k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1285 root 25 0 9272 6892 1312 R 29.3 0.7 0:00.88 bzip2 1276 root 18 0 3048 860 1372 R 3.7 0.1 0:05.25 cp 7 root 15 0 0 0 0 S 0.7 0.0 0:00.27 pdflush 6 root 15 0 0 0 0 S 0.3 0.0 0:00.11 pdflush 8 root 15 0 0 0 0 S 0.3 0.0 0:00.06 kswapd0 300 root 15 0 0 0 0 S 0.3 0.0 0:00.24 kjournald 1064 mgs2 16 0 8144 2276 6808 S 0.3 0.2 0:00.69 sshd 1224 root 16 0 4964 1360 3944 S 0.3 0.1 0:00.03 bash 1275 mgs2 16 0 2840 936 1784 R 0.3 0.1 0:00.15 top 1284 root 15 0 2736 668 1416 S 0.3 0.1 0:00.01 tar 1 root 16 0 2624 520 1312 S 0.0 0.1 0:06.51 init

Table 16-2. top:interactive commands

Command

Function

A

Sorts processes by age (newest first).

h or ?

Displays a Help screen.

k

Prompts for a PID number and type of signal and sends the process that signal. Defaults to signal 15 (SIGTERM); specify 9 (SIGKILL) only when 15 does not work.

M

Sorts processes by memory usage.

P

Sorts processes by CPU usage (default).

q

Quits.

s

Prompts for time between updates in seconds. Use 0 for continuous updates.

SPACE

Updates the display immediately.

T

Sorts tasks by time.

W

Writes a startup file named ~/.toprc so that next time you start top, it uses the same parameters it is currently using.

Категории