The top command can be used to view processes in real time.
[root@server1 ]# top top - 21:46:14 up 2 days, 29 min, 2 users, load average: 0.31, 0.40, 0.54 Tasks 160 total, 1 running, 158 sleeping, 0 stopped, 0 zombie %Cpu(s): 4.5 us, 2.2 sy, 1.5 ni, 90.0 id, 4.8 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem: 3067824 total, 1498976 used, 1560456 free, 54168 buffers KiB Swap: 3104837 total, 0 used, 3104872 free, 85747 cached Mem PID User PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMANDS 4594 root 20 0 417768 144754 5803 S 6.0 5.2 0:41:49 Xorg 2488 User1 20 0 92281 85793 84739 S 3.3 4.5 1:04:77 gnome-term 3794 User1 20 0 144384 209193 48473 S 5.7 3.2 0:32:99 firefox . . .
In the interactive TOP window, the < and > characters can be used to toggle through the columns, sorting the column.
In top, press k (kill) to start the process of killing a process. A prompt will appear. If you want to kill the default pid, you simply will just press enter. If you want to kill a different PID, type the other PID, and press enter.
PID to signal/kill [default pid = 12345]
Another prompt will appear. Press enter to use the default signal of 15 (terminate). If you want to use a different signal, type the signal number you want to use, and press enter.
Send pid 12345 signal [15/sigterm]
- kill -1 (hang up)
- kill -2 (interrupt)
- kill -3 (quit)
- kill -9 (kill)
- kill -15 (terminate)
Non interactive mode
By default, top is interactive, or real time. The -n1 option can be used to display a snap shot of top.
It is worth mentioning that when using the -n1 option, the data displayed may differ from the data that is displayed when running top in interactive mode. For example, the Cpu(s) column in interactive mode may show an average CPU usage of less than 1%, whereas the CPU usage in non-interactive mode may be much higher. For this reason, the sar command may be better suited for some non-interactive data collection.
~]# top -n1
If using non-interactive top in a bash shell script, the -b (batch) option must be used in order for cron to be able to produce output.