System Monitoring Utilities

Contents

13.1. Debugging
13.2. Files and File Systems
13.3. Hardware Information
13.4. Networking
13.5. The /proc File System
13.6. Processes
13.7. System Information
13.8. User Information
13.9. Time and Date

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 > or # sign prompt). Omissions 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.

Debugging

Specifying the Required Library: ldd

Use the command ldd to find out which libraries would be loaded by the dynamic executable specified as argument.

tux@mercury:~> ldd /bin/ls
	linux-vdso.so.1 =>  (0x00007fff1ddff000)
	librt.so.1 => /lib64/librt.so.1 (0x00007f1315993000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f1315776000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007f131556e000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f1315215000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f1314ff9000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f1315b9c000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f1314df5000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007f1314bf0000)

Static binaries do not need any dynamic libraries.

tux@mercury:~> ldd /sbin/ldconfig
        not a dynamic executable
tux@mercury:~> file /bin/sash
/sbin/ldconfig: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for \
 GNU/Linux 2.6.4, statically linked, stripped

Library Calls of a Program Run: ltrace

The command ltrace enables you to trace the library calls of a process. This command is used in a similar fashion to strace. The parameter -c outputs the number and duration of the library calls that have occurred:

tux@mercury:~> ltrace -c find ~
    seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 57.49   40.170338        1580     25411 __fprintf_chk
 11.50    8.036963         237     33894 readdir
  7.18    5.019464          98     50822 __ctype_get_mb_cur_max
  6.02    4.206130         767      5480 fchdir
  3.30    2.304577         209     11022 malloc
  3.18    2.224551         406      5479 __open_2
[...]
  0.00    0.000025          25         1 __cxa_atexit
------ ----------- ----------- --------- --------------------
100.00   69.878004                363666 total

System Calls of a Program Run: strace

The utility strace enables you to trace all the system calls of a process currently running. Each line of the command's output contains the system call name, followed by its arguments in parenthesis, and its return value. Enter the command in the normal way, adding strace at the beginning of the line:

tux@mercury:~> strace ls
execve("/bin/ls", ["ls"], [/* 52 vars */]) = 0
brk(0)                                  = 0x618000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) \
	= 0x7f9848667000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) \
	= 0x7f9848666000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=200411, ...}) = 0
mmap(NULL, 200411, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f9848635000
close(3)                                = 0
open("/lib64/librt.so.1", O_RDONLY)     = 3
[...]
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) \
	= 0x7f9848508000
write(1, "bin\nDesktop\nDocuments\n", 22bin
Desktop
Documents
) = 22
close(1)                                = 0
munmap(0x7f9848508000, 4096)            = 0
close(2)                                = 0
exit_group(0)

For example, to trace all attempts to open a particular file, use the following:

tux@mercury:~> strace -e open ls .bashrc
open("/etc/ld.so.cache", O_RDONLY)       = 3
open("/lib64/librt.so.1", O_RDONLY)      = 3
open("/lib64/libselinux.so.1", O_RDONLY) = 3
open("/lib64/libacl.so.1", O_RDONLY)     = 3
open("/lib64/libc.so.6", O_RDONLY)       = 3
open("/lib64/libpthread.so.0", O_RDONLY) = 3
[...]

To trace all the child processes, use the parameter -f. The behavior and output format of strace can be largely controlled. For information, see man strace.