How to monitor all processes in a Linux/UNIX system
In Category Command Line
The Linux system provides a command called “top” which provides dynamic real-time view of running processes, memory status, cpu usage and other system information. This command is very easy to use and it updates the display automatically and user just needs to keep the command open. Then user needs to press the key “q” to close the display.
Here is the output of “top” command look like.
Tasks: 179 total, 1 running, 178 sleeping, 0 stopped, 0 zombie Cpu(s): 7.2%us, 2.6%sy, 0.0%ni, 88.5%id, 1.5%wa, 0.1%hi, 0.0%si, 0.0%st Mem: 2007980k total, 1046836k used, 961144k free, 55852k buffers Swap: 803208k total, 0k used, 803208k free, 539948k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3175 neo 20 0 215m 93m 22m S 5.8 4.8 3:36.28 firefox 2501 root 20 0 81052 10m 5580 S 1.9 0.5 2:10.15 Xorg 2927 neo 20 0 161m 23m 12m S 1.9 1.2 0:07.07 knotify4 2964 neo 20 0 138m 28m 15m S 1.9 1.4 0:06.24 konsole 3527 neo 20 0 2556 996 736 R 1.9 0.0 0:00.01 top 1 root 20 0 2008 768 564 S 0.0 0.0 0:01.14 init 2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 15 -5 0 0 0 S 0.0 0.0 0:00.25 ksoftirqd/0 5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 6 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1 7 root 15 -5 0 0 0 S 0.0 0.0 0:00.24 ksoftirqd/1 8 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/1 9 root 15 -5 0 0 0 S 0.0 0.0 0:00.94 events/0 10 root 15 -5 0 0 0 S 0.0 0.0 0:00.86 events/1 11 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khelper 85 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/0 86 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kintegrityd/1 88 root 15 -5 0 0 0 S 0.0 0.0 0:00.26 kblockd/0 89 root 15 -5 0 0 0 S 0.0 0.0 0:00.03 kblockd/1 91 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kacpid 92 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kacpi_notify 164 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 cqueue 168 root 15 -5 0 0 0 S 0.0 0.0 0:00.51 ata/0 169 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 ata/1 170 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 ata_aux 172 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 ksuspend_usbd 177 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 khubd 180 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kseriod 222 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pdflush 223 root 20 0 0 0 0 S 0.0 0.0 0:00.08 pdflush
The first line of output tells you the total number of tasks or processes currently running in the system and their process states.
The second line tells you about the CPU usage in the system and the percentage of states in which CPU spent its time. The states are explained below.
| Code | Meaning |
|---|---|
| us | user |
| sy | system |
| ni | nice |
| id | idle |
| wa | I/O wait state |
| hi | hardware interrupt |
| si | software interrupt |
| st | steal |
The third and fourth lines tell you about the RAM and Swap usage respectively. Then follows the list of processes ordered by CPU and memory usage.
The meaning of following line explained below:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
| Code | Meaning |
|---|---|
| PID | The unique process ID |
| USER | Name of the user who owns this process |
| PR | Priority of the process. Read More |
| NI | Nice value. A negative value means higher priority. |
| VIRT | Total amount of virtual memory used by this process in KBytes |
| RES | Non-swapped memory (Resident memory size) in KBytes |
| SHR | Amount of shared memory used by this process in KBytes |
| S | Status of the process.
D = Uninterruptible sleep R = Running S = Sleeping T = Traced or Stopped Z = Zombie |
| %CPU | CPU share of this process since last screen update |
| %MEM | Current share of available physical memory (RES) |
| TIME+ | Total CPU time used since the process started. |
| COMMAND | Name of the command or process name |
There is no special option provided by “top” to limit the number of processes. However using “watch”, “head” and “tail” commands, you can monitor exactly top 10 processes as shown below. You need to press “Ctrl+C” to close the display.
[neo@techpulp ~]$ watch -n 1 "top -b -n 1 | head -n 17 | tail -n 11" Every 10.0s: top -b -n 1 | head -n 17 | tail -n 11 Thu Jan 29 23:20:19 2009 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3175 neo 20 0 225m 103m 22m S 7.8 5.3 6:24.63 firefox 2501 root 20 0 82948 12m 6700 S 2.0 0.6 5:25.48 Xorg 3253 neo 20 0 107m 19m 9868 S 2.0 1.0 2:40.87 npviewer.bin 3839 neo 20 0 2424 972 720 R 2.0 0.0 0:00.01 top 1 root 20 0 2008 768 564 S 0.0 0.0 0:01.15 init 2 root 15 -5 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0 4 root 15 -5 0 0 0 S 0.0 0.0 0:00.53 ksoftirqd/0 5 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 6 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/1 [neo@techpulp ~]$
Can some one explain meaning of VIRT RES SHR tokens..
It will be god if you explain PR too.
Updated the article for the info you asked for..!