The top command is a great way to keep track of processes executing on a system in real-time.
Launch top by entering this on the command line.
$ top
Here is an example of what you will see.
top - 09:13:11 up 1:29, 2 users, load average: 0.20, 0.16, 0.10 Tasks: 85 total, 1 running, 84 sleeping, 0 stopped, 0 zombie Cpu(s): 2.5%us, 1.0%sy, 0.0%ni, 96.0%id, 0.0%wa, 0.4%hi, 0.1%si, 0.0%st Mem: 4050364k total, 459920k used, 3590444k free, 17028k buffers Swap: 1956612k total, 0k used, 1956612k free, 174940k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5521 root 20 0 897m 49m 8924 S 7 1.3 8:18.19 X 5574 ryan 20 0 139m 21m 10m S 2 0.6 0:48.17 compiz 5932 ryan 20 0 142m 18m 9876 S 1 0.5 0:00.28 Terminal 5589 ryan 20 0 174m 86m 19m S 0 2.2 1:37.46 firefox-bin 1 root 20 0 3712 580 492 S 0 0.0 0:01.14 init 2 root 15 -5 0 0 0 S 0 0.0 0:00.00 kthreadd 3 root RT -5 0 0 0 S 0 0.0 0:00.00 migration/0 4 root 15 -5 0 0 0 S 0 0.0 0:00.04 ksoftirqd/0 5 root RT -5 0 0 0 S 0 0.0 0:00.00 migration/1 6 root 15 -5 0 0 0 S 0 0.0 0:00.02 ksoftirqd/1
The ‘-d delay‘ option will change the amount of time between updates.
This will set the delay for half a second.
$ top -d 0.5
The ‘-n iterations‘ option allows you to define the number of iterations it displays before it exits. It is handy when you want to see a single snapshot of the system. To do this, enter this command.
$ top -n 1
The ‘-u user‘ option allows you to view the processes of a single user
$ top -u ryan
The ‘-p PID‘ option shows you a specific process or group of processes by listing their process IDs.
$ top -p 1001
$ top -p 1001,1002,1003
By default top is launched in interactive mode. In this mode you can submit commands that will change the behavior of the program.
Pressing ‘f‘ will allow you to select what fields to display.
You will see a screen similar to this.
Current Fields: AEHIOQTWKNMbcdfgjplrsuvyzX for window 1:Def Toggle fields via field letter, type any other key to return * A: PID = Process Id * E: USER = User Name * H: PR = Priority * I: NI = Nice value * O: VIRT = Virtual Image (kb) * Q: RES = Resident size (kb) * T: SHR = Shared Mem size (kb) * W: S = Process Status * K: %CPU = CPU usage * N: %MEM = Memory usage (RES) * M: TIME+ = CPU Time, hundredths b: PPID = Parent Process Pid c: RUSER = Real user name d: UID = User Id f: GROUP = Group Name g: TTY = Controlling Tty j: P = Last used cpu (SMP) p: SWAP = Swapped size (kb) l: TIME = CPU Time r: CODE = Code size (kb) s: DATA = Data+Stack size (kb) u: nFLT = Page Fault count v: nDRT = Dirty Pages count y: WCHAN = Sleeping in Function z: Flags = Task Flags* X: COMMAND = Command name/line
Similarly, ‘o‘ will allow you to change the order of the fields that are currently displayed.
If you have multiple CPUs or processor cores the pressing ‘1‘ will give you more individual information on each one.
top - 11:58:37 up 1:34, 2 users, load average: 0.17, 0.13, 0.09 Tasks: 87 total, 2 running, 85 sleeping, 0 stopped, 0 zombie Cpu0 : 5.7%us, 1.5%sy, 0.0%ni, 92.1%id, 0.3%wa, 0.2%hi, 0.1%si, 0.0%st Cpu1 : 5.4%us, 1.5%sy, 0.0%ni, 92.3%id, 0.4%wa, 0.2%hi, 0.1%si, 0.0%st Mem: 4050364k total, 510172k used, 3540192k free, 17264k buffers Swap: 1956612k total, 0k used, 1956612k free, 245704k cached
You can exit by pressing Ctrl-C.