Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of the Linux ps command

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article analyzes "what is the use of the Linux ps command"? The content is detailed and easy to understand. Friends who are interested in "what is the use of the Linux ps command" can follow the editor's train of thought to read it slowly and deeply. I hope it will be helpful to everyone after reading. Let's follow the editor to learn more about "what is the use of Linux ps commands?"

The ps command is the most commonly used command for monitoring processes, which allows you to view the details of all running processes on the system.

The ps command can be used in many different ways, which often confuses beginners. Posts asking about the syntax of ps commands are common on various Linux forums, and this is due to UNIX's long history and large factions. The syntax of the ps command varies from one Linux release to another, so Linux has adopted a compromise approach that combines different styles with users who are already used to using ps commands on other systems.

The basic format of the ps command is as follows:

[root@localhost ~] # ps aux

# View all processes in the system and use the BS operating system format

[root@localhost ~] # ps-le

# View all the processes in the system and use the Linux standard command format

Options:

A: displays all processes of a terminal, except for session leads

U: displays the home user of the process and memory usage

X: displays the process without the control terminal

-l: displays more detailed information in a long format

-e: show all processes

As you can see, the ps command is a little different, and some of its options cannot be added with "-", such as the command "ps aux", where "aux" is the option, but it cannot be preceded by a "-".

If you execute the "man ps" command, you will find that the help of the ps command in order to adapt to different UNIX-like systems, there are many formats available, which are not convenient to remember. Therefore, I suggest you remember a few fixed options. For example:

"ps aux" can view all the processes in the system

"ps-le" can view all processes in the system, and can also see the PID and process priority of the parent process of the process.

"ps-l" can only see the processes generated by the current Shell

These three commands are enough, let's take a look at each of them.

[example 1]

[root@localhost ~] # ps aux# View all processes in the system USER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.0 0.2 2872 1416? Ss Jun04 0:02 / sbin/initroot 2 0.0 0.0 0 0? S Jun04 0:00 [kthreadd] root 3 0.0 0.0 00? S Jun04 0:00 [migration/0] root 4 0.0 0.0 00? S Jun04 0:00 [ksoftirqd/0]... Omit part of the output.

The specific meaning of each column in the above output information is listed in Table 1.

Table 1 meaning of output information of ps command

The header means USER by which user the process was generated. ID of the PID process. % CPU the percentage of CPU resources consumed by the process, the higher the percentage, the more resources the process consumes. % MEM the percentage of physical memory consumed by the process, the higher the percentage, the more resources the process consumes. VSZ the amount of virtual memory consumed by the process, in KB. RSS the amount of actual physical memory occupied by the process, in KB. TTY the terminal on which the process is running. Among them, tty1~ tty7 represents the local console terminal (different terminals can be switched by Alt+F1 ~ F7 shortcut keys), tty1~tty6 is the local character interface terminal, and tty7 is the graphics terminal. Pts/0 represents a virtual terminal, usually a remote connection terminal. The first remote connection occupies pts/0, and the second remote connection occupies pts/1, which is longer in turn. STAT process status. The common states are as follows:

-D: a sleep state that cannot be awakened, usually used in the case of Ipicuro.

-R: the process is running.

-S: the process is asleep and can be awakened.

-T: stopped state, may be paused in the background or the process is in debug state.

-W: memory interaction state (invalid since 2.6 kernel).

-X: dead process (should not occur).

-Z: zombie process. The process has been aborted, but some programs are still in memory.

-

-N: low priority.

-L: locked in memory.

-s: contains child processes.

-l: multithreading (lowercase L).

-+: located in the background.

START the start time of the process. TIME this process takes up CPU computing time, and note that it is not system time. COMMAND generates the command name for this process.

[example 2] the "ps aux" command can see all the processes in the system, and the "ps-le" command can also see all the processes in the system. Because of the "- l" option, the "ps-le" command can see more detailed information, such as the PID of the parent process, priority, and so on. But the basic functions of the two commands are the same, and it is enough to master one of them.

[root@localhost] # ps-leF S UID PID PPID C PRI Nl ADDR SZ WCHAN TTY TIME CMD4 S 01 00 800-718 -? 00:00:02 init1 S 02 00 800-0-- 00:00:00 kthreadd1 S 0 3 20-40-0 -? 00:00:00 migration/01 S 0 4 20 800-0 -? 00:00:00 ksoflirqd/01 S 0 520-40-0 -? 00:00:00 migration/0... Omit part of the output.

Table 2 lists the meaning of each column in the above output information.

Table 2 ps-le command output information

The header means the F process flag, indicating the permissions of the process. There are two common flags:

1: the process can be copied, but cannot be executed

4: the process uses superuser privileges

S process status. The specific state is the same as the STAT state in the "psaux" command; UID the ID;PPID parent process of the user's ID;PID process running this process ID;C the CPU utilization of the process in percentage; the priority of the PRI process, the lower the value, the higher the priority of the process and the earlier it is executed by CPU; the priority of the NI process, the lower the value, the earlier the process is executed; where is the ADDR process in memory? SZ how much memory is consumed by the process; WCHAN whether the process is running. " -"stands for running; TTY which terminal generates the process; TIME the process takes up CPU computing time, not system time; CMD generates the command name of this process.

[example 3] if you don't want to see all the processes, but just want to see which processes are generated by the current login, you only need to use the "ps-l" command:

[root@localhost ~] # ps-l # View the process generated by the current login F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD4 S 0 18618 18614 0 800-1681-pts/1 00:00:00 bash4 R 0 18683 18618 4 800-1619-pts/1 00:00:00 ps

As you can see, logging in from the pts/1 virtual terminal produces only two processes: one is the Shell generated after login, that is, bash;, and the other is the ps command that is being executed.

Let's talk about the zombie process again. Generally, the generation of zombie process is due to abnormal stop or programming error, which causes the child process to end before the parent process, and the parent process does not recycle the child process correctly, so that the child process exists in memory all the time. This is the zombie process.

The zombie process will have an impact on the stability of the host, so after generating the zombie process, be sure to optimize the software that generates the zombie process to avoid generating the zombie process all the time; for the zombie process that has already been generated, can be forced to abort after it is found.

About what the Linux ps command is useful to share here, I hope that the above content can make you improve. If you want to learn more knowledge, please pay more attention to the editor's updates. Thank you for following the website!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report