Top: dynamically observe process changes. ps indicates the process status at a certain time point, while top indicates dynamically observe the running status of the process in real time. We can divide the result of the top command into three parts, which is roughly like the following. The first part is the overall statistics of the system. The first line is the task queue...
Top: dynamically observe process changes
Ps is the state of the process at a certain time point, while top is the dynamic real-time observation of the running state of the process.
We can divide the result of the top command into three parts, which is roughly like the following.
The first part is the overall statistics of the system.
The first line is the task queue information (top), which is the same as the execution result of the uptime Command. The content is as follows:
Last-21:50:37 current time
Up system running time, format: minute
1 user current login user count
Load average: 0.00, 0.00, 0.00 system load, that is, the average length of the task queue.
The three values are the average values from 1 minute, 5 minutes, and 15 minutes ago to the present.
What is the standard of this load? it seems that everyone's statement is not consistent. some say that the number of CPU cores cannot exceed. if it exceeds, the load will be high.
It is also said that the three values are divided by 3 and cannot exceed 0.6. if the value is greater than, the load is high. what kind of standards can only be observed on the server? You can also discuss this issue.
The content of the second action process (Tasks) is as follows:
Tasks: 97 total process count
1. number of running processes of running
96 sleeping sleep processes
0 stopped process count
0 zombie botnets
Cpu (s) information. The content is as follows:
Cpu (s): 0.7% us (user mode) CPU usage
0.3% sy (system mode) kernel CPU usage
0.0% CPU usage percentage of processes whose priorities have changed during ni (nice) user processes
99.7% idle task idle CPU percentage
0.0% wa (I/O waiting) percentage of CPU time waiting for input and output (I/O problems, will seriously affect your server performance, because I/O consumes CPU)
0.0% hi (servicing IRQs)
0.3% si (servicing soft IRQs)
0.0% st (steal (time given to other DomU instances ))
The above three items are related to IRQ (the full name of IRQ is Interrupt Request, and the translation into Chinese is "Interrupt Request"). because I am not a computer professional, these items are for me, it is a little difficult, so I recommend an article: Work Load balancing with IRQ SMP Affinity, which can help you understand. The interrupt information in the system is in/proc/irq/, and the interrupt request is in/proc/interrupts. if you want to study it in depth, you can view other relevant information on your own.
The fourth line (Mem) is the memory information. The content is as follows:
Mem: 245408 k total physical memory
Total physical memory used by 215148 k used
30260 k free memory total
Memory usage of 58532 k buffers as Kernel Cache
The fifth line (Swap) is the Swap zone information. The content is as follows:
Swap: 262136 k total number of Swap areas
Total number of swap areas used by 0 k used
262136 k free swap zone total
The total number of swap areas of the 52320 k cached buffer.
The second part is the TOP internal command prompt bar:
Top internal commands can control the display mode of processes. In the top command status, enter the corresponding internal commands. The following are commonly used:
S. change the top command refresh frequency (default value: 3 seconds)
Change delay from 3.0 to: Enter the corresponding number at this time.
L disable or enable the first line of top information
T. disable or enable the second line of Tasks and the third line of Cpus information.
M: disable or enable the first part of the fourth line of Mem and the fifth line of Swap information.
N indicates the process list in the order of PID size
P lists processes in the order of CPU usage
M lists processes in the order of memory usage
R reverses the arrangement.
U displays the processes of the specified user. by default, all user processes are displayed.
C. display the full path of the process. by default, only the process name is displayed.
N or # set the number of processes displayed in the process list, but the maximum number is full screen.
F. adjust the top command to display the list items. Such as adding a GROUP column or UID column. However, the next time you use the top command, it turns out to be the default one.
K. terminate the process.
R adjusted the process priority (Linux and AIX are from-20 to 19, HP-UX is 0 to 39), as to how to get it, you can view through man nice.
H Show Help
Q: Exit top.
For the above internal commands, we recommend that you try them first, so it will be much easier to learn! Remember, you must learn more about Linux.
Process list information area in part 3
The details of each process are displayed at the bottom of the statistics area. First, let's take a look at the meaning of each column.
Column name meaning
PID process id
PPID parent process id
RUSER Real user name
User ID of the UID process owner
USER: USER name of the process owner
GROUP name of the GROUP process owner
The terminal name of the TTY startup process. Processes not started from the terminal are displayed?
PR priority
NI nice value. Negative value indicates high priority, positive value indicates low priority (Linux and AIX are from-20 to 19, HP-UX is 0 to 39)
P indicates the last CPU used, which is only meaningful in multiple CPU environments.
% Percentage of CPU time used since the last CPU update to the present
Total cpu time used by the TIME process, in seconds
TIME + total cpu time used by the process, in the unit of 1/100 seconds
% MEM percentage of physical memory used by the process
Total virtual memory used by the VIRT process, in kb. VIRT = SWAP + RES
The SWAP size in the virtual memory used by the SWAP process, in kb.
The size of the physical memory used by the RES process, not swapped out, in kb. RES = CODE + DATA
Physical memory occupied by CODE executable CODE, in kb
Physical memory occupied by parts other than the DATA executable code (DATA segment + stack), in kb
Size of SHR shared memory, in kb
Number of nFLT page errors
The number of modified pages that the last time the data is written to the present.
S process status
D = uninterrupted sleep
R = run
S = sleep
T = tracking/stopping
Z = Zombie process
COMMAND name/COMMAND line
If the process is sleep, WCHAN displays the system function name in sleep.
Flags task flag
By default, only important PID, USER, PR, NI, VIRT, RES, SHR, S, % CPU, % MEM, TIME +, and COMMAND columns are displayed. You can use the internal f command we mentioned above to adjust the list options.
The following describes two common top options,
-B: execute the top command in batches. Generally, the output results of batches are output as files in combination with the raw orientation.
-N: used with-B, that is, the number of top outputs.
For example
[Root @ yufei ~] # Top-B-n 1> topfile
Then we can use
[Root @ yufei ~] # More topfile
To view the content of the entire top, make up for what we mentioned above. the display is full screen at most. we can view all the content through the combination of the above two parameters.
Pgrep filters process information
Pgrep is a tool used to query processes by program names. it is generally used to determine whether a program is running. In server configuration and management, this tool is often used and simple and clear.
Format: pgrep parameter option program name
Common parameters
-L list the program name and process ID;
-The ID of the start of the o process;
-N indicates the ID of the process to terminate;
-U user's process ID;
[Root @ yufei ~] # Pgrep-lo httpd
1628 httpd
[Root @ yufei ~] # Pgrep-ln httpd
1637 httpd
[Root @ yufei ~] # Pgrep-l httpd
1628 httpd
1630 httpd
1631 httpd
1632 httpd
1633 httpd
1634 httpd
1635 httpd
1636 httpd
1637 httpd
View a user's process
[Root @ yufei ~] # Pgrep-lU apache
1630 httpd
1631 httpd
1632 httpd
1633 httpd
1634 httpd
1635 httpd
1636 httpd
1637 httpd