Linux System Information
System Processes
The ps ax command displays a list of current system processes, including processes owned by other users. To display the owner of the processes along with the processes use the command ps aux. This list is a static list; in other words, it is a snapshot of what is running when you invoked the command. If you want a constantly updated list of running processes, use top as described below.
The ps output can be long. To prevent it from scrolling off the screen, you can pipe it through less:
ps aux | lessYou can use the ps command in combination with the grep command to see if a process is running. For example, to determine if emacs is running, use the following command:
ps ax | grep emacsThe top command displays currently running processes and important information about them including their memory and CPU usage. The list is both real-time and interactive. An example of top's output is provided as follows:
00:53:01 up 6 days, 14:05, 3 users, load average: 0.92, 0.87, 0.71 71 processes: 68 sleeping, 2 running, 1 zombie, 0 stopped CPU states: 18.0% user 0.1% system 16.0% nice 0.0% iowait 80.1% idle Mem: 1030244k av, 985656k used, 44588k free, 0k shrd, 138692k buff 424252k actv, 23220k in_d, 252356k in_c Swap: 2040212k av, 330132k used, 1710080k free 521796k cached PID USER PRI NI size RSS SHARE STAT %CPU %MEM TIME COMMAND 15775 joe 5 0 11028 10M 3192 S 1.5 4.2 0:46 emacs 14429 root 15 0 63620 62M 3284 R 0.5 24.7 63:33 X 17372 joe 11 0 1056 1056 840 R 0.5 0.4 0:00 top 17356 joe 2 0 4104 4104 3244 S 0.3 1.5 0:00 gnome-terminal 1 root 0 0 544 544 476 S 0.0 0.2 0:06 init 2 root 0 0 0 0 0 SW 0.0 0.0 0:00 kflushd 3 root 1 0 0 0 0 SW 0.0 0.0 0:24 kupdate 4 root 0 0 0 0 0 SW 0.0 0.0 0:00 kpiod 5 root 0 0 0 0 0 SW 0.0 0.0 0:29 kswapd 347 root 0 0 556 556 460 S 0.0 0.2 0:00 syslogd 357 root 0 0 712 712 360 S 0.0 0.2 0:00 klogd 372 bin 0 0 692 692 584 S 0.0 0.2 0:00 portmap 388 root 0 0 0 0 0 SW 0.0 0.0 0:00 lockd 389 root 0 0 0 0 0 SW 0.0 0.0 0:00 rpciod 414 root 0 0 436 432 372 S 0.0 0.1 0:00 apmd 476 root 0 0 592 592 496 S 0.0 0.2 0:00 automountTo exit top, press the [q] key.
Useful interactive commands that you can use with top include the following:
Command Description [Space] Immediately refresh the display [h] Display a help screen [k] Kill a process. You will be prompted for the process ID and the signal to send to it. [n] Change the number of processes displayed. You will be prompted to enter the number. [u] Sort by user. [M] Sort by memory usage. [P] Sort by CPU usage. Table 26-1. Interactive top commands
Application such as Mozilla and Nautilus are thread-aware — multiple threads are created to handle multiple users or multiple requests, and each thread is given a process ID. By default, ps and top only display the main (initial) thread. To view all threads, use the command ps -m or type [Shift]-[H] in top.
File Systems
The df command reports the system's disk space usage. If you type the command df at a shell prompt, the output looks similar to the following:
Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda2 10325716 2902060 6899140 30% / /dev/hda1 15554 8656 6095 59% /boot /dev/hda3 20722644 2664256 17005732 14% /home none 256796 0 256796 0% /dev/shmBy default, this utility shows the partition size in 1 kilobyte blocks and the amount of used and available disk space in kilobytes. To view the information in megabytes and gigabytes, use the command df -h. The -h argument stands for human-readable format. The output looks similar to the following:
Filesystem Size Used Avail Use% Mounted on /dev/hda2 9.8G 2.8G 6.5G 30% / /dev/hda1 15M 8.5M 5.9M 59% /boot /dev/hda3 20G 2.6G 16G 14% /home none 251M 0 250M 0% /dev/shmIn the list of partitions, there is an entry for /dev/shm. This entry represents the system's virtual memory file system.
The du command displays the estimated amount of space being used by files in a directory. If you type du at a shell prompt, the disk usage for each of the subdirectories will be displayed in a list. The grand total for the current directory and subdirectories will also be shown as the last line in the list. If you do not want to see the totals for all the subdirectories, use the command du -hs to see only the grand total for the directory in human-readable format. Use the du --help command to see more options.
Monitoring File Systems
Red Hat Linux provides a utility called diskcheck that monitors the amount of free disk space on the system. Based on the configuration file, it will send email to the system administrator when one or more disk drives reach a specified capacity. To use this utility, have the diskcheck RPM package installed.
This utility is run as an hourly cron task.
The following variables can be defined in /etc/diskcheck.conf:
>
- defaultCutoff — When disk drives reach this percent capacity, it will be reported. For example, if defaultCutoff = 90, an email will be sent when the monitored disk drives reach 90% capacity.
- cutoff[/dev/partition] — Override the defaultCutoff for the partition. For example, if cutoff['/dev/hda3'] = 50 is specified, diskcheck will alert the system administrator when the partition /dev/hda3 reaches 50% capacity.
- cutoff[/mountpoint] — Override the defaultCutoff for the mount point. For example, if cutoff['/home'] = 50 is specified, diskcheck will alert the system administrator when the mount point /home reaches 50% capacity.
- exclude — Specify one or more partitions for diskcheck to ignore. For example, if exclude = "/dev/sda2 /dev/sda4" is specified, diskcheck will not alert the system administrator if /dev/sda2 or /dev/sda4 reaches the specified cutoff percentage.
- ignore — Specify one or more file system types to ignore in the format -x filesystem-type. For example, if ignore = "-x nfs -x iso9660" is specified, the system administrator will not be alerted about nfs or iso9660 file systems reaching capacity.
- mailTo — Email address of the system administrator to alert when partitions and mount points reach the specified capacity. For example, if mailTo = "webmaster@example.com" is specified, webmaster@example.com will be emailed alerts.
- mailFrom — Specify the identity of the email sender. This is useful if the system administrator wants to filter the mail from diskcheck. For example, if mailFrom = "Disk Usage Monitor" is specified, email will be sent to the system administrator with the sender Disk Usage Monitor.
- mailProg — Specify the mail program to use to send email alerts. For example, if mailProg = "/usr/sbin/sendmail" is specified, Sendmail will be used as the mail program.
You do not have to restart a service if you change the configuration file because it is read each time the cron task is run. You must have the crond service running for cron tasks to be executed. To determine if the daemon is running, use the command /sbin/service crond status. It is recommended that you start the service at boot time.
Hardware
You can use the lspci command to list all PCI devices. Use the command lspci -v for more verbose information or lspci -vv for very verbose output.
For example, lspci can be used to determine the manufacturer, model, and memory size of a system's video card:
01:00.0 VGA compatible controller: Matrox Graphics, Inc. MGA G400 AGP (rev 04) (prog-if 00 [VGA]) Subsystem: Matrox Graphics, Inc. Millennium G400 Dual Head Max Flags: medium devsel, IRQ 16 Memory at f4000000 (32-bit, prefetchable) [size=32M] Memory at fcffc000 (32-bit, non-prefetchable) [size=16K] Memory at fc000000 (32-bit, non-prefetchable) [size=8M] Expansion ROM at 80000000 [disabled] [size=64K] Capabilities: [dc] Power Management version 2 Capabilities: [f0] AGP version 2.0The lspci is also useful to determine the network card in your system if you do not know the manufacturer or model number.
Memory Usage
The free command displays the total amount of physical memory and swap space for the system as well as the amount of memory that is used, free, shared, in kernel buffers, and cached.
total used free shared buffers cached Mem: 256812 240668 16144 105176 50520 81848 -/+ buffers/cache: 108300 148512 Swap: 265032 780 264252The command free -m shows the same information in megabytes, which are easier to read.
total used free shared buffers cached Mem: 250 235 15 102 49 79 -/+ buffers/cache: 105 145 Swap: 258 0 258