Chapter 36. System Monitoring Utilities

Table of Contents

36.1. List of Open Files: lsof
36.2. User Accessing Files: fuser
36.3. File Properties: stat
36.4. USB Devices: lsusb
36.5. Information about a SCSI Device: scsiinfo
36.6. Processes: top
36.7. Process List: ps
36.8. Process Tree: pstree
36.9. Who Is Doing What: w
36.10. Memory Usage: free
36.11. Kernel Ring Buffer: dmesg
36.12. File Systems and Their Usage: mount, df, and du
36.13. The /proc File System
36.14. vmstat, iostat, and mpstat
36.15. procinfo
36.16. PCI Resources: lspci
36.17. System Calls of a Program Run: strace
36.18. Library Calls of a Program Run: ltrace
36.19. Specifying the Required Library: ldd
36.20. Additional Information about ELF Binaries
36.21. Interprocess Communication: ipcs
36.22. Time Measurement with time

Abstract

A number of programs and mechanisms, some of which are presented here, can be used to examine the status of your system. Also described are some utilities that are useful for routine work, along with their most important parameters.

For each of the commands introduced, examples of the relevant outputs are presented. In these examples, the first line is the command itself (after the dollar sign prompt). Comments are indicated with square brackets ([...]) and long lines are wrapped where necessary. Line breaks for long lines are indicated by a backslash (\).

$ command -x -y
output line 1
output line 2
output line 3 is annoyingly long, so long that \
    we have to break it
output line 3
[...]
output line 98
output line 99

The descriptions have been kept short to allow as many utilities as possible to be mentioned. Further information for all the commands can be found in the man pages. Most of the commands also understand the parameter --help, which produces a brief list of the possible parameters.

36.1. List of Open Files: lsof

To view a list of all the files open for the process with process ID PID, use -p. For example, to view all the files used by the current shell, enter:

$ lsof -p $$
COMMAND  PID USER   FD   TYPE DEVICE    SIZE     NODE NAME
zsh     4694   jj  cwd    DIR   0,18     144 25487368 /suse/jj/t (totan:/real-home/jj)
zsh     4694   jj  rtd    DIR    3,2     608        2 /
zsh     4694   jj  txt    REG    3,2  441296    20414 /bin/zsh
zsh     4694   jj  mem    REG    3,2  104484    10882 /lib/ld-2.3.3.so
zsh     4694   jj  mem    REG    3,2   11648    20610 /usr/lib/zsh/4.2.0/zsh/rlimits.so
[...]
zsh     4694   jj  mem    REG    3,2   13647    10891 /lib/libdl.so.2
zsh     4694   jj  mem    REG    3,2   88036    10894 /lib/libnsl.so.1
zsh     4694   jj  mem    REG    3,2  316410   147725 /lib/libncurses.so.5.4
zsh     4694   jj  mem    REG    3,2  170563    10909 /lib/tls/libm.so.6
zsh     4694   jj  mem    REG    3,2 1349081    10908 /lib/tls/libc.so.6
zsh     4694   jj  mem    REG    3,2      56    12410 /usr/lib/locale/de_DE.utf8/LC_TELEPHONE
[...]
zsh     4694   jj  mem    REG    3,2      59    14393 /usr/lib/locale/en_US/LC_NUMERIC
zsh     4694   jj  mem    REG    3,2  178476    14565 /usr/lib/locale/en_US/LC_CTYPE
zsh     4694   jj  mem    REG    3,2   56444    20598 /usr/lib/zsh/4.2.0/zsh/computil.so
zsh     4694   jj    0u   CHR 136,48               50 /dev/pts/48
zsh     4694   jj    1u   CHR 136,48               50 /dev/pts/48
zsh     4694   jj    2u   CHR 136,48               50 /dev/pts/48
zsh     4694   jj   10u   CHR 136,48               50 /dev/pts/48

The special shell variable $$, whose value is the process ID of the shell, has been used.

The command lsof lists all the files currently open when used without any parameters. Because there are often thousands of open files, listing all of them is rarely useful. However, the list of all files can be combined with search functions to generate useful lists. For example, list all used character devices:

$ lsof | grep CHR
sshd       4685    root  mem    CHR    1,5             45833 /dev/zero
sshd       4685    root  mem    CHR    1,5             45833 /dev/zero
sshd       4693      jj  mem    CHR    1,5             45833 /dev/zero
sshd       4693      jj  mem    CHR    1,5             45833 /dev/zero
zsh        4694      jj    0u   CHR 136,48                50 /dev/pts/48
zsh        4694      jj    1u   CHR 136,48                50 /dev/pts/48
zsh        4694      jj    2u   CHR 136,48                50 /dev/pts/48
zsh        4694      jj   10u   CHR 136,48                50 /dev/pts/48
X          6476    root  mem    CHR    1,1             38042 /dev/mem
lsof      13478      jj    0u   CHR 136,48                50 /dev/pts/48
lsof      13478      jj    2u   CHR 136,48                50 /dev/pts/48
grep      13480      jj    1u   CHR 136,48                50 /dev/pts/48
grep      13480      jj    2u   CHR 136,48                50 /dev/pts/48

SUSE LINUX Administration Guide 9.3