Linux ps command example summary

  
                

The Linux ps command is mainly used to check the running process of the system, and determine whether the state machine running the process occupies too many resources. The following small series through the examples to give you a detailed introduction to the Linux ps command, together to understand.

Linux provides the current process at the same time, such as user ID, CPU usage, memory usage, command name, etc., it is not Detailed real-time data, such as top or htop command is displayed. However, even if the function and output are simple, it is still a must-have process management/monitoring tool. Every Linux novice should know this and study hard. In this article, we'll use the ps command to view processes, filter, and sort them in different ways to enhance the underlying parts.

Syntax Note:

The ps command comes in two different styles, BSD and UNIX. New users often confuse and misinterpret these two styles. So to figure them out, here are some basic information before proceeding.

Note: & ldquo;ps aux” is not the same as “ps -aux”. For example, “-u” is used to display the user's process. But “u” is showing detailed information.

BSD Style: No hyphens in front of BSD-style grammar options.

ps aux

UNIX/LINUX style: There is a dash in front of the linux-style syntax option. …

ps -ef

Mixing the grammatical styles of two Linux systems is a good thing. For example, & ldquo;ps ax” In this article, we will focus on the UNIX-style syntax.

How to use the ps command?

1. Display all processes:

The following command will list all processes

$ ps ax

$ ps -ef

Add the pipe output to less, to scroll through the

“u” or “-f” parameters to display the details of all processes

$ ps aux

$ ps -ef -f

Note: Why does the user column not display my username, but other users, such as root, www, etc., for all usernames (including you) if the length is greater than 8 The character, then ps will only display the UID, not the username.

2, according to the user display process:

is used by the user of the process using &l“&rdq” user name to display. Multiple usernames can be provided separated by commas.

$ ps -f -u www-data

UID PID PPID C STIME TTY TIME CMD

www-data 1329 1328 0 09:32 ? 00:00:00 nginx: worker process

www-data 1330 1328 0 09:32 ? 00:00:00 nginx: worker process

www-data 1332 1328 0 09:32 ? 00:00:00 nginx: worker process

www-data 1377 1372 0 09:32 ? 00:00:00 php-fpm: pool a.localhost

www-data 1378 1372 0 09:32 ? 00:00:00 php-fpm: pool a.localhost

www-data 4524 2359 0 10:03 ? 00:00:00 /usr/sbin/apache2 -k start

www-data 4527 2359 0 10:03 ? 00:00:00 /usr/sbin/apache2 -k start

www-data 4528 2359 0 10:03 ? 00:00:00 /usr/sbin/apache2 -k start

3. Display the process by name and process ID:

Search for the process by name or command, use &l“& Rdq” plus search terms.

$ ps -C apache2

PID TTY TIME CMD

2359 ? 00:00:00 apache2

4524 ? 00:00:00 apache2

4525 ? 00:00:00 apache2

. . .

4, sort according to CPU or memory:

Department administrators often want to find processes that consume a lot of memory or CPU. Sorting options sort the list of processes based on specific fields or parameters.

“–sort&r” Multiple fields separated by commas can be specified. In addition, this field can be prefixed with &l“rdquo; or &l”dquo; symbols, indicating descending or ascending ordering. There are many parameters to sort through the process list, you can check the full list of man pages.

$ ps aux --sort=-pcpu,+pmem

Shows the top 5 CPU processes that consume most of them.

$ ps aux --sort=-pcpu

Copyright © Windows knowledge All Rights Reserved