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 are the ways to use the Linux ps command

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

Share

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

This article mainly explains "what is the use of the Linux ps command". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the use of the Linux ps command?"

The ps command in Linux is an abbreviation for Process Status. The ps command is used to list the processes currently running on the system. The ps command lists snapshots of the current processes, those at the time of the execution of the ps command.

There are five states of a process on Linux: running (running or waiting in the run queue) interrupting (dormant, blocked, waiting for a condition to be formed or receiving a signal) uninterruptible (unawakable and unrunnable, the process must wait until an interrupt occurs) deadlock (the process has been terminated, but the process descriptor exists Stop until the parent process calls wait4 () system call (stop running after the process receives SIGSTOP, SIGSTP, SIGTIN, SIGTOU signals) the ps tool identifies the five status codes of the process: r run runnable (on run queue) S interrupt sleepingD uninterruptible uninterruptible sleep (usually IO) T stop traced or stoppedZ zombie a defunct ("zombie") processps use

Usage: ps [parameters]

The ps command has many parameters, as follows:-A displays all processes (equivalent to-e) (utility)-a shows all processes of a terminal, except for the session leader-N ignores the selection. -d shows all processes, but omits all session leads (utility)-x shows processes without control terminals, and shows the specific path of each command. Dx is not available. (utility)-the time that the p pid process uses cpu-u uid or username selects a valid user id or username-g gid or groupname to display all processes in the group. U username displays all processes under the user and displays the detailed paths of each command. For example, ps U zhang; (utility)-f is all listed and is usually used in conjunction with other options. For example: ps-fa or ps-fx and so on.-l long format (with fields such as Frech wchanje C etc.)-j job format-o user-defined format. V display in virtual memory format s display in signal format-m display all threads-H display process hierarchy (in conjunction with other commands, such as: ps-Ha) (utility) e command after the display environment (e.g. ps-d e; ps-an e) (utility) h does not display the first line-version display version information-help display help information

Here are a few ps commands that you use more in your daily life.

1. Ps-aux

The most common method is ps-aux, and then use a pipe symbol to direct to grep to find a specific process, and then operate on a specific process.

Column description:

USER: user name PID: process ID (Process ID)% CPU: process cpu occupancy% MEM: process memory usage VSZ: size of virtual memory used by the process (Virtual Size) RSS: the size of the resident set or the actual memory used by the process, in Kbytes bytes. TTY: terminal associated with the process (tty) STAT: status of the process: status of the process expressed in characters (status code of STAT) TIME: total cpu time used by the process COMMAND: command line command being executed

2. Ps-axjf

The process is displayed in a tree, and sometimes we want to display the process in a tree structure, using the-axjf parameter.

Ps-axjf

Or you can use another command.

Pstree

3. Ps-ef

The process is displayed in a standard format in the following format

Column description:

UID: user ID (User ID) PID: process ID (Process ID) PPID: parent process ID (Parent Process id) STIME: startup time TTY: terminal associated with the process (tty) TIME: total cpu time used by the process CMD: command line command in progress

4. Ps-l

Column description:

F: represents the flag of the program (flag), 4 represents the user as super userS: sleep Sleeping dormant, blocked, waiting for a condition to be formed or to receive a signal. UID: user ID (User ID) PID: process ID (Process ID) PPID: parent process ID (Parent Process id) C: percentage of resources used by CPU PRI: this is the abbreviation of Priority (priority execution order), NI: this is the Nice value, in the next section we will continue to introduce ADDR: this is kernel function, indicating which part of the program is in memory. If it is a running program, it is generally "-" SZ: the amount of memory used WCHAN: whether this program is currently running, if so-indicates that it is running TTY: login terminal location TIME: used CPU time. What are the instructions issued by CMD?

5. Show all current processes

(1), ps-ax

Use the-a parameter, where-a stands for all. At the same time, the x parameter will show the process without the control terminal.

(2), ps-ax | less

The result of this command may be long. For ease of viewing, you can use it in combination with less commands and pipes.

6. Filter processes through cpu and memory usage

If you want to filter the results by CPU or memory usage, you can find out which process is taking up your resources. To do this, we can use the aux parameter to display comprehensive information:

(1), ps-aux | less

Display comprehensive information

When the results are long, we can use pipes and less commands to filter.

The default result set is unsorted and can be sorted with the-sort command.

(2) sort in ascending order according to CPU use

$ps-aux-sort-pcpu | less

Sort by cpu usage

(3) sort in ascending order according to memory usage

$ps-aux-sort-pmem | less

Sort by memory usage

(4) We can also merge them into one command and display the first five results through the pipeline:

Ps-aux-sort-pcpu,+pmem | head-n 5

At this point, I believe you have a deeper understanding of "what is the use of the Linux ps command?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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