Chapter 29. System Monitoring Utilities

Table of Contents

29.1. List of Open Files: lsof
29.2. User Accessing Files: fuser
29.3. File Properties: stat
29.4. Processes: top
29.5. Process List: ps
29.6. Process Tree: pstree
29.7. Who Is Doing What: w
29.8. Memory Usage: free
29.9. Kernel Ring Buffer: dmesg
29.10. File Systems and Their Usage: mount, df, and du
29.11. The /proc File System
29.12. procinfo
29.13. PCI Resources: lspci
29.14. System Calls of a Program Run: strace
29.15. Library Calls of a Program Run: ltrace
29.16. Specifying the Required Library: ldd
29.17. Additional Information about ELF Binaries
29.18. Interprocess Communication: ipcs
29.19. 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 by the use of 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.

29.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. Usually a huge number of files will be open. To find out how many files are open, enter the following:

$ lsof | wc -l
3749

List all the character devices used with:

$ 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 9.2