590
◾
Linux with Operating System Concepts
of nonvoluntary context switches. Voluntary context switches
arise when the process will-
ingly surrenders the processor to the next process because of I/O requirements while a
nonvoluntary context switch occurs when the timer, which is timing the amount of CPU
time each process receives, reaches 0.
The uptime program reports on the duration that the system has been running (since
the last boot/reboot). The output is presented in a single line that states the current time,
the number of days, hours, and minutes of uptime, the number of current users (logged in),
and the average load over the past 1, 5, and 15 minutes.
The strace program may or may not be useful as a troubleshooting tool, but it is an inter-
esting program. As stated in Chapter 8, applications software and
portions of the operating
system invoke the kernel through system calls. System calls are the same as function calls
in a C program except that the calls are made to the kernel rather than to a function within
the running software. The strace program will map the number and nature of system calls
of a given Linux command.
As an example, using strace on pwd results in a listing of the system calls made by pwd.
The output includes the parameters passed to those functions. Pwd calls, in order, brk,
mmap, access, open, fstat, mmap, close, open, read, fstat, mmap, mprotect, mmap (4 times),
arch_prctl, mprotect (twice), munmap, brk (twice), open, fstat, mmap, close, getcwd, fstat,
mmap, write, close, munmap, close, and exit_group.
What strace is doing is invoking the Linux command and tracing what
the command
does while it executes. It intercepts and records the system calls to list them as the result
of strace. Strace is primarily used as a debugging tool for those who are writing Linux
commands but can be used by system administrators to troubleshoot problems within the
operating system itself. Chances are, if you have installed a stable version of Linux and you
are not modifying Linux, you would not need to resort to strace. However, it can help you
identify what a command is doing.
14.4.4 Memory System-Monitoring Tools
The program vmstat reports on memory and virtual memory usage. The default report is
broken into six sections:
•
Process information
• Memory usage
• Swap space usage
• I/O usage
• System usage
• CPU usage
These values are all averages, as computed since the last time the system was booted. What
follows is an example of vmstat’s output (edited to fit within the space below).
Maintaining and Troubleshooting Linux
◾
591
procs- - - -memory- - - - -swap- - - -io- - - system- - - cpu- - -
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 2 64 112976 65360 413114 0 0 71 30 203 60 2 1 85 0 0
Table 14.3 describes the meaning of the abbreviations in the header. Explanations follow
for some of the terms following the table.
As Linux is a
multitasking operating system, it is possible and likely that more than one
process will be in some state of execution at any time. As covered in Chapter 4, this means
that there are several active processes although the CPU is only executing one process at
any moment. It switches off between them. The number of waiting processes (r) are those
that are active (loaded in memory) but not being executed at that moment by the CPU
while those in uninterruptible sleep (b) are uninterruptible processes that are waiting on
hardware. Interrupting such a process when it is executing could damage data. Portions of
the kernel run in uninterruptible sleep.
The cs value indicates how many context switches occur per second. Recall that there
are several reasons for a context switch.
In multitasking, the system timer will interrupt the
CPU to force a context switch between a running process and a waiting process. A switch
can also occur when one process terminates or requires time-consuming I/O and so volun-
tarily surrenders the CPU. Additionally, altering process priority, while not forcing a con-
text switch, will alter the amount of time a process executes before it undergoes a switch.
The four values us, sy, id, and wa provide the amounts of time
that the processor is pro-
cessing user processes, is processing system processes, is idle (no process executing), and is
waiting on I/O. Finally,
cycle stealing
is a situation where the CPU is forced to wait for some
I/O process to complete. This often happens with DMA (direct memory access) I/O when
TABLE 14.3
vmstat Output Information
Do'stlaringiz bilan baham: