top: Dynamically view process changes
Please reprint from the source: http://eksliang.iteye.com/blog/2166641
Compared with ps, which selects the process state at a point in time, top can continuously detect the state of the process running. The method of use is as follows:
top [-d number] | top [-bnp] parameter: -d: The number of seconds can be followed by the number of seconds that the entire process interface is updated. Default is 5 seconds -n: In combination with -b, the meaning is that several top output results are required. -p: Specify certain PIDs for viewing and monitoring only. Key commands that can be used during top execution: ?: Displays the key commands that can be entered in top P: Displayed in order of CPU usage resources M: Displayed in order of memory usage resources N: sort by PID T: Sorted by the accumulated CPU time (TIME+) used by the process K: Give a PID a signal (signal); r: re-customize a nice value for a PID q: button to leave the top software
The top program can continuously detect the working status of the process of the entire system. By default, the time for each update of process resources is 5 seconds, however, you can use -d to modify it. Top is mainly divided into two interfaces. The upper part of the interface is the resource usage status of the entire system, and the lower part of the interface is the resource usage of each process.
Enter the top command directly in the terminal as follows:
top - 17:32:50 up 12:09, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 83 total, 1 running, 82 sleeping, 0 stopped, 0 zombie Cpu (s): 0.0%us, 0.7%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1030680k total, 854936k used, 175744k free, 76468k buffers Swap: 2064376k total, 0k used, 2064376k free, 453240k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 595 root 20 0 0 0 0 S 0.3 0.0 0:01.45 flush-8:0 1490 root 20 0 28372 3980 3288 S 0.3 0.4 0:54.73 vmtoolsd 1 root 20 0 2900 1444 1224 S 0.0 0.1 0:01.77 init .....omit
First look at the first half: a total of five lines
The first line (top): The information displayed in this line is:
The time of the current system, that is, 17:32:50; the time elapsed so far from the boot, that is, up 12:09;
1 user: the number of people currently logged in to the system;
load average: 0.00, 0.00, 0.00: The average load of the system in the last 1, 5, and 15 minutes.
The second line (tasks): This line shows the total number of processes and the status of the process
83 total | total number of processes |
1 running | Number of running processes |
82 sleeping | Number of suspended processes |
0 stopped | Number of stopped processes |
0 zombie | Number of zombie processes |
The third line (Cpu(s)): This line shows the overall load of the cpu
0.0%us | The percentage of CPU occupied by user space |
0.7% sy | The percentage of system space occupied by CPU |
0.0% ni | The percentage of CPU occupied by processes that have changed priorities in user space |
99.3%id | Idle CPU percentage |
0.0% wa | Percentage of processes waiting for I/O input and output |
The fourth line (Mem): Indicates the current system physical memory usage
1030680k total | total physical memory |
854936k used | total memory used |
17616k free | total memory remaining |
76468k buffers | Amount of memory used as kernel cache |
The fifth line (Swap): Indicates the current system virtual memory usage
2064376k total | total amount of virtual memory |
0k used | The total amount of virtual memory used |
2064376k free | The total amount of remaining virtual memory |
453240k cached | Buffer size for swapping between physical memory and virtual memory |
Looking at the second half: resource usage of each process
PID | process id |
USER | Username of the process owner |
PR NI | The priority of these two representative processes, the smaller the probability of being grabbed by the CPU in the same time slice, the greater the probability |
VIRT | The total amount of virtual memory used by the process, in kb. VIRT=SWAP+RES |
RES | The size of the physical memory used by the process but not swapped out, in kb |
SHR | Shared memory size, in kb |
S | Process status. D=uninterruptible sleep state, R=running, S=sleep, T=track/stop, Z=zombie process |
%CPU | The percentage of CPU used since the last update |
%MEM | The percentage of physical memory used by the process |
COMMAND | command name |
Top uses the CPU usage (%CPU) to sort by default. I generally like to use the memory usage to sort. At this time, you can press "M", and if you want to restore it, press "P".
If you want to output the results of top to a file, you can do this
Reference example : Execute the top information twice, and then redirect the content to ./top.txt
[root@localhost test]# top -b -n 2 >> ./top.txt
参考实例:查看单一进程
我们自己的bash PID可由$$变量获得,使用top持续查看该PID
[root@localhost test]# echo $$ 8612 [root@localhost test]# top -p 8612
参考实例:修改进程的优先级
在上述实例中,直接按下r之后,会出现如下图所示
这个时候输入PID号码,按回车,这个时候输入10,如下图所示
看到没有,NI,进程的优先级已经由0变成了10