Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use ps command in Linux system

Shulou Source: shulou.com Published: 2022-06-01 13:52:54 10月23日 Update

Editor to share with you how to use the ps command in the Linux system, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

The ps (process status) command in linux is the most commonly used and powerful process viewing command under LINUX. Using this command, you can determine which processes are running and running state, whether the process ends, whether the process is dead or not, which processes occupy too much resources, and so on. The ps command is most commonly used to monitor the work of background processes.

Ps command by default

When we type the ps command on the terminal, we don't provide that much information:

By default, only the process ID (Process ID, PID) of the program, the terminal on which they are running (TTY), and the CPU time spent by the process are displayed.

Basic introduction to ps command

First, let's take a look at man ps's explanation:

The syntax of UNIX, BSD and GUN is supported by using GNU ps command in Linux system:

1, UNIX style, options can be combined together, and the option must have "-" hyphen 2, BSD style, options can be combined together, but the option can not have "-" hyphen. BSD is a branch of Unix 3, a GNU-style long option preceded by two "-" hyphens. The GUN project, which later developed the Linux123456 syntax format: ps [parameters]

Common parameters:

-A displays all processes (same as-e)-a displays all processes of the current terminal-u displays user information of processes-o displays process information in user-defined form-f displays relationships between programs 12345

For an introduction to more parameters, you can use the command man ps to view it, and I won't repeat it here.

Using the ps command is not about remembering all the available parameters, but about remembering those that are most useful.

Field meaning

Before introducing the example, we need to understand the meaning of the fields output by the ps command so that we can better understand the information displayed. The basic meanings of common fields are as follows:

User name of the owner of the USER process PID process ID (Process ID) START process activation time% cpu usage of the CPU process% percentage of memory used by the MEM process the amount of virtual memory used by the VSZ process, the size of the RSS resident space in K. Displays the number of K bytes of programs that currently reside in memory. TTY the terminal (tty) STAT process status associated with the process, including the following: d non-interruptible Uninterruptible sleep (usually IO) R is running Or the process S in the queue is dormant T stops or is tracked Z zombie process W enters memory swap (invalid since kernel 2.6) X dead process common usage

To show all the processes, use ps-An or ps-aux.

There is a lot of information above, and other parts are skipped. If you have a lot of process information, you may not be able to display a page, so you can use the more command. For example:

Insert a picture description here

You can also display all processes and output them to a ps.txt file:

Ps-aux > ps.txt

From the above information, you can see more detailed information about the owner of the process, cpu usage, memory usage, and so on.

Display basic information for all processes

Most Linux system administrators have their own set of parameters that they keep in mind to extract useful process information. For example, if you want to see all the processes running on the system, you can use the-ef parameter combination. For example:

There is a lot of information above, and other parts are skipped. To save space.

Find specific process information

Ps-ef | grep sshps-aux | grep ssh

At this point, you need to use it with grep. For example, check the process related to "ssh":

Displays the process of the specified user

Insert a picture description here

Sort processes by viewing the usage of CPU resources

The default result set is not sorted. You can sort through the sort command.

❝

Ps-aux | sort-nk 3

The above is all the contents of the article "how to use ps commands in Linux system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Process command information parameter system memory run content status user terminal face style meaning field common use situation usage program article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Microsoft NVidia Linux