System performance monitoring Tool-Ps/pstree

Source: Internet
Author: User
Tags uppercase character

Ps

1) Let the system report detailed information.

When using the PS command, if you do not take any optional options, the information displayed is very limited and often shows only the programs that the current user is running. When a system administrator needs to know more detailed information about the operation of the application, such as to know the application memory and CPU occupancy, then you need to add some options. If the system administrator needs to see the applications executed by other users together, it is necessary to use the optional-al after this command. In this case, all programs running on the system are listed. If you want to know the CPU and memory usage of a program, rather than simply the actual CPU usage time, then you need to add the parameter-l to this command, that is, using theThe PS–L command allows the system to display detailed operational information for the application。 If you are interested, you can check the relevant help for the meaning of the above fields. In general, the system administrator is concerned about the program's PID number, memory and CPU usage, the name of the command, the user's terminal and so on. Other information is not of great value to system administrators.

2) View the programs running in the background.
by default, the PS command displays only the programs that are running in the foreground, and does not show programs running in the background. However, not all programs are run in the foreground. Under normal circumstances, the number of programs that are hidden in the background is much larger than the program running in the foreground. Many system-brought programs that start as the operating system starts are run in the background. And sometimes, the system problems are often caused by background programs. such as the common Trojans and other programs are running in the background. For this reason, the system administrator is more interested in knowing which programs are running in the background.
If you want to see the programs running in the background, it's a little more complicated. Because in different versions of the Linux operating system, it is possible to display background processes with different options. As in Red Hat Linux operating system, in fact, the form of parameters rather than optional. that usesPS aux command can show all applications (including foreground and background)the difference between the parameter and the optional option is mainly in front and without this-symbol. If this symbol is represented, this is an optional option. And if it doesn't, it means it's a parameter.。 This symbol cannot be saved under normal circumstances. In the place where the write is not written, or do not need to add, the system will prompt the error message, saying that the command could not be found. In other versions of the Linux system, this aux parameter may not be recognized. As in some Linux operating system versions, you need to use the-a option to accomplish this task. Due to the differences between the system versions, the system administrator has brought a lot of trouble. Fortunately, there are online help in each operating system version. If your system administrator uses a new version of the operating system and does not know which option to use for all processes, you can use commands such as PS--heip to view system help. However, the drawback is that the system online Help is English, the system administrator's English level is a very small test. However, if you want to be a Linux system administrator, this English language is still needed. Because the newest Linux technology basically comes out in English document first. In fact, to master the most advanced operating system books, most of the computer books are in English.

3) Sort the list of programs.
When running applications for a long time, the system administrator needs to sort the application. The sorting function of the PS command is relatively strong. Mainly because this command has a--sort parameter (note that in front of this parameter is the two small crossbar symbols, readers should not think that the author is wrong). After this parameter, you can sort by adding the sort fields that the system administrator wants. As this commandps–a--sort cmd, it means displaying all of the system's applications and sorting according to the program commands. In the Linux operating system parameters, there is a more troublesome thing, is that the parameter case is different often represents a different meaning. As the above command, the uppercase A is replaced by lowercase character A, the result is completely different. Uppercase character A represents all applications, and lowercase character a means "all w/tty except session leaders". There is an essential difference between the two. This difference can be used to filter the applications that are running on different terminal login accounts.

[[Email protected] ~]# PS aux
[Email protected] ~]# Ps-la
[[Email protected] ~]# PS AXJF
Options/Parameters:

-W display widen to show more information
-au Show more detailed information
-aux Show all itineraries that contain other users
-A show all processes (equivalent to-e) (utility)
-a displays all processes of a terminal, in addition to session leader
-N ignores selection.
-D displays all processes, but omits all session leaders (utility)
-X displays a process that does not control the terminal, and displays the specific path of each command. DX cannot be combined. (utility)
-p PID process uses CPU time
-U uid or username Select a valid user ID or user name
-G gid or groupname displays all processes for the group.
U username Displays all processes under the user, and displays the detailed path of each command. such as: PS U Zhang; (utility)
-F is all listed, and is usually used with other options. such as: Ps-fa or Ps-fx and so on.
-L long format (with fields such as F,wchan,c)
-J Job Format
-o user-defined format.
V display in virtual memory format
s displayed in signal format
-M Show All threads
-H displays the level of the process (shared with other commands, such as: ps-ha) (utility)
The e command then displays the environment (for example: ps-d e; Ps-a e) (utility)
H does not display the first line

l long format output;
U displays the process in the order of the user name and start time;
J Use the task format to display the process;
F to display the process in a tree-shaped format;
A shows all processes of all users (including other users);
X shows the process without control terminal;
R shows the running process;
WW avoids detailed parameters being truncated;

PS Command common usage (easy to see system processes)
1) PS A shows all the programs under the current terminal, including other users ' programs.
2) ps-a shows all processes.
3) PS C lists the program, displaying the actual instruction name of each program, without including the path, parameter, or indication of the resident service.
4) Ps-e The effect of this parameter is the same as specifying the "A" parameter.
5) When a program is listed in PS E, the environment variables used by each program are displayed.
6) PS F Displays the tree structure with ASCII characters, expressing the relationship between the programs.
7) ps-h displays a tree structure that represents the inter-program relationship.
8) ps-n displays all programs except the ones under the PS command Terminal.
9) PS s uses program signal format to display program status.
) PS S lists programs, including interrupted sub-program data.
One) ps-t< terminal number > Specify the terminal number, and lists the status of the program belonging to the terminal.
) PS U Displays the status of the program in a user-oriented format.
() PS x displays all programs and does not differentiate them by terminal.
14) The most common approach is to Ps-aux, and then use a pipe symbol to direct to grep to find a specific process and then manipulate the specific process.

Special Note:
Because PS can support a lot of OS type, so his parameters are much more outrageous! And there is no plus-a lot worse! The detailed usage should refer to man PS Oh!
Example one: Present your own current login PID and related information listed (front desk)
[Email protected] ~]# ps-l
F S UID PID PPID C PRI NI ADDR SZ Wchan TTY time CMD
0 S 0 5881 5654 0 0-1303 wait pts/0 00:00:00 su
4 S 0 5882 5881 0 0-1349 wait pts/0 00:00:00 bash
4 R 0 6037 5882 0 0-1111-pts/0 00:00:00 PS
The above information is actually a lot of! The meanings of the relevant information are:
F represents the flag of this procedure, 4 represents the user as Super user;
S represents the state of the program (STAT);
PID is the ID of this program Ah! The ppid on the bottom is the ID of the parent program;
Percentage of resources used by the C CPU
PRI this is the abbreviation for priority (precedence order);
NI this is nice value;
ADDR This is the kernel function, which points out the part of the program that is in memory. If it is a running program, it is generally "-"!
The amount of memory used by SZ;
Wchan whether the procedure is currently in operation, and if so-indicates that it is in operation;
The terminal location of the TTY login;
Time used to consume the CPU.
What are the instructions given by CMD!?
Carefully see each of the program's PID and ppid of the relevance of why Oh! Among the three programs listed above, there is a correlation between the two.

Example two: List all currently in-memory programs:
[[Email protected] ~]# PS aux
USER PID%cpu%MEM VSZ RSS TTY STAT START time COMMAND
Root 1 0.0 0.1 1740 540? S Jul25 0:01 init [3]
Root 2 0.0 0.0 0 0? SN Jul25 0:00 [ksoftirqd/0]
Root 3 0.0 0.0 0 0? s< Jul25 0:00 [events/0]
..... The middle is omitted .....
Root 5881 0.0 0.3 5212 1204 pts/0 S 10:22 0:00 su
Root 5882 0.0 0.3 5396 1524 pts/0 S 10:22 0:00 Bash
Root 6142 0.0 0.2 4488 916 pts/0 r+ 11:45 0:00 PS aux
The meanings of the relevant information are:
User: Does the process belong to that user account?
PID: The number of the process.
%CPU: The percentage of CPU resources that the process uses off;
%MEM: The percentage of physical memory occupied by the process;
VSZ: The amount of virtual memory that the process uses (Kbytes)
RSS: The amount of fixed memory that the process occupies (Kbytes)
TTY: The process is operating on that terminal, if it is not related to the terminal, then display?, the other tty1-tty6 is the login program above the machine, if it is pts/0 and so on is represented by the network connection into the host program.
STAT: The current state of the program, the main state is:
R: The program is currently in operation or may be operational;
S: The program is currently sleeping (can be said to be idle!) ), but can be awakened by certain signals (signal).
T: The program is currently being detected or is stopped;
Z: The program should have been terminated, but the parent program could not properly terminate him, causing the state of the zombie (Xinjiang Corpse) program

I: Free Idle
D: Non-interruptible uninterruptible sleep (ususally IO) receives a signal that does not wake up and is not operational, and the process must wait until an interrupt occurs.
T: Terminate Terminate process received Sigstop, SIGSTP, Sigtin, Sigtou signal after stop running.
P: Wait for Exchange page
W: No-resident page has no resident pages there is not enough memory paging to allocate.
X: Dead Process
<: High-priority process with high-priority processes
N: Low-priority process with lower priority sequence
L: Memory Lock page Lock has memory paged out and shrunk in memory
S: Leader of the process (under it there are sub processes);
L: Multi-process (using Clone_thread, similar to NPTL pthreads)
+: Process groups in the background

Start: The time at which the process is triggered to start;
Time: The process actually uses the CPU to operate.
Command: What is the actual instruction of the program?

Example three: Displays all the programs in sample one:
[Email protected] ~]# Ps-la
F S UID PID PPID C PRI NI ADDR SZ Wchan TTY time CMD
4 S 0 1 0 0 76 0-435-? 00:00:01 Init
1 S 0 2 1 0 94 19-0 Ksofti? 00:00:00 ksoftirqd/0
1 S 0 3 1 0 70-5-0 worker? 00:00:00 events/0
..... The following omit .....

Example four: Lists programs similar to the program tree display:  
[[email protected] ~]# ps-axjf 
PPID PID pgid SID TTY tpgid STAT UID time COMM and 
0 1 0 0?-1 S 0 0:01 init [3] 
1 2 0 0?-1 SN 0 0:00 [ksoftirqd/0] 
..... Middle omitted ...  
1 5281 5281 5281?-1 SS 0 0:00/usr/sbin/sshd 
5281 5651 5651 5651?-1 SS 0 0:00 \_ SSHD:DMT sai[priv] 
5651 5653 5651 5651?-1 S 0:00 \_ sshd: [email protected]/0 
5653 5654 5654 5654 pts/ 0 6151 Ss 0:00 \_-bash 
5654 5881 5881 5654 pts/0 6151 S 0 0:00 \_ su 
5881 5882 5882 5654 pts/0 6151 S 0 0:00 \_ bash 
5882 6151 6151 5654 pts/0 6151 r+ 0 0:00 \_ ps-axjf 
You can also use Pstree to reach this program tree.

Example five: Find out the PID numbers related to cron and syslog services?
[[Email protected] ~]# PS aux | Egrep ' (cron|syslog) '
Root 1539 0.0 0.1 1616 616? Ss Jul25 0:03 syslogd-m 0
Root 1676 0.0 0.2 4544 1128? Ss Jul25 0:00 Crond
Root 6157 0.0 0.1 3764 664 pts/0 r+ 12:10 0:00 egrep (cron|syslog)
So the numbers are 1539 and 1676 of these two

Pstree
[Email protected] ~]# Pstree [-aup]
Parameters:
-A: Connections between each program tree are connected in ASCII characters;
-P: And also list the PID of each process;
-U: Also lists the name of the account that each process belongs to.
Example one: Lists the dependencies of all the program trees on the current system:
[Email protected] ~]# Pstree

Example two: Show the PID and users at the same time
[Email protected] ~]# Pstree-aup
Within the brackets () is the PID and the program's owner! However, since I am using ROOT to execute this instruction, it is possible that the root may not be displayed

System performance monitoring Tool-Ps/pstree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.