Linux Process: PS command

Source: Internet
Author: User

In normal times, the linux Process is usually used. So I studied how to use the linux ps command. I will share it with you here, hoping it will be useful to you.

BKJIA recommended for editing: Linux monitoring tools

1. ps OverviewThe two commands who and w are used to view the current system user situation. Let's take a look at the process. This is also the topic of this chapter. To monitor and control processes, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic and very powerful linux Process viewing command. You can use this command to determine which processes are running and running, whether the process is terminated, whether the process is dead, and which processes are occupying excessive resources. In short, most of the information can be obtained by executing this command.

2. ps command and its parameters

The most common ps command is used to monitor the working conditions of background processes, because background processes do not communicate with standard input/output devices such as the screen keyboard, so if you need to detect the situation, you can use the ps command.

The syntax format of this command is as follows: ps [Option]

The following describes the Command Options:

◆-E: all processes are displayed.

◆-F full format.

◆-H no title is displayed.

◆-L long format.

◆-W width output.

◆ A: displays all processes on the terminal, including those of other users.

◆ R only displays running processes.

◆ X shows the process without control of the terminal.

O [+ |-] k1 [, [+ |-] k2 [,…] The process list is displayed based on the multilevel sorting sequence specified by the shortcut KEYS in short keys, k1, and k2. The default sequence is specified for different ps formats. The default sequence can be overwritten by the user's specified sequence. The "+" character is optional, and the "-" character is used to reverse the direction of the specified key.

Pids only lists the conditions of the specified process. Process IDs are separated by commas. The process list must be followed by the last option of the command line parameter. spaces cannot be inserted in the middle. For example, ps-f1, 4, 5.

The following describes the long command line options, all of which start:

◆ -- Sort X [+ |-] key [, [+ |-] key [,…] Select a multiple KEYS from the sort keys segment. The "+" character is optional, because the default direction is to sort the numbers in ascending order or the dictionary is responsible for 1 hot Shu? Ps-jax-sort = uid,-ppid, + pid.

◆ -- Help: displays help information.

◆ -- Version: displays the version information of the command.

The sort key is mentioned in the preceding option description, and further describes the sort key. Note that the values used in sorting are internal values used by ps, not only pseudo values in some output formats.

Sort Key List

Short format

Long format

Description

◆ Simple executable name of c-cmd

◆ C-cmdline complete command line

◆ F-flags Long MODE flag

◆ G-pgrp Process Group ID

◆ G-tpgid: Control tty Process Group ID

◆ J-cutime cumulative user time

◆ J-cstime cumulative system time

◆ K-utime user time

◆ K-stime system time

◆ Number of m-min_flt secondary page errors

◆ Number of M-maj_flt Main Page errors

◆ N-cmin_flt accumulative secondary page Error

◆ N-cmaj_flt accumulative Main Page Error

◆ O-session dialog ID

◆ P-pid process ID

◆ P-ppid parent process ID

◆ R-rss resident size

◆ R-resident page

◆ S-size memory size in kilobytes)

◆ Number of S-share pages

◆ T-ttytty secondary device number

◆ T-start_time process startup time

◆ U-uid-UID

◆ U-user Name

◆ V-vsize total number of virtual memory bytes)

◆ Y-priority kernel scheduling priority

3. Common ps Command Parameters

The parameters described in the previous two sections may make readers feel a little scary. In fact, this is a very easy-to-use command. Generally, users only need to master some of the most common command parameters. The three most commonly used parameters are u, a, and x. The following uses an example to describe their usage.

Log on to the system as root to view the current process status

$ Ps

PID TTY TIME COMMAND

5800 ttyp0 00:00:00 bash

5835 ttyp0 00:00:00 ps

The displayed items are divided into PID process ID, TTY terminal name, TIME process execution TIME, and COMMAND line input ).

Use the u option to view the process owner and other details, as shown below:

$ Ps u

User pid % CPU % MEM USZ RSS TTY STAT START TIME COMMAND

Test 5800 0.0 0.4 1892 1040 ttyp0 S Nov27-bash

Test 5836 0.0 0.3 2528 856 ttyp0 R Nov27 ps u

There is a horizontal line in front of the bash process, which means that the process is the user's login shell, so for a login user, there is only one process with a short line. The options % CPU and % MEM are also displayed. The former indicates the percentage of CPU time and total time occupied by the process, and the latter indicates the percentage of memory and total memory occupied by the process.

In this case, we can see all the processes that control the terminal. However, we still haven't observed other processes that do not control the terminal. Therefore, we need to use the x option. Use the x option to view all processes.

The following example uses the x option:

$ Ps x

PID TTY STAT TIME COMMAND

5800 ttyp0 S-bash

5813 ttyp1 S-bash

5921 ttyp0 S man ps

5922 ttyp0 S sh-c/usr/bin/gunzip-c/var/catman/cat1/ps.1.gz |/

5923 ttyp0 S/usr/bin/gunzip-c/var/catman/cat1/ps.1.gz

5924 ttyp0 S/usr/bin/less-is

5941 ttyp1 R ps x

We can find that there are so many more processes at once. These extra processes are processes that do not control terminals.

All the processes shown above are owned by the test user. In fact, many other users are using the system, which naturally corresponds to many other processes. If you want to know about these processes, you can use option a to view all processes of all users in the current system. The aux combination option is often used, which shows the most detailed process.

$ Ps aux

User pid % CPU % MEM VSZ RSS TTY STAT START TIME COMMAND

Root 1 0.0 0.0 1136 64? S Nov25 0: 02 init [3]

Root 2 0.0 0.0 0 0? SW Nov25 0: 00 [kflushd]

Root 3 0.0 0.0 0 0? SW Nov25 0: 03 [kupdate]

Root 4 0.0 0.0 0 0? SW Nov25 0: 00 [kpiod]

Root 5 0.0 0.0 0 0? SW Nov25 0: 00 [kswapd]

Root 163 0.0 0.1 1628 332? S Nov25 0: 02 sshd

Root 173 0.0 0.0 1324 200? S Nov25 0: 00 syslogd

Root 181 0.0 0.0 1420 0? SW Nov25 0: 00 [klogd]

Daemon 191 0.0 0.1 1160 312? S Nov25 0: 00/usr/sbin/atd

Root 201 0.0 0.1 1348 492? S Nov25 0: 00 crond

Root 212 0.0 0.0 1292 68? S Nov25 0: 00 inetd

......

At the top of the display is the process of other users. We can see users such as root and daemon and the processes they started. In the preceding example, we introduce some of the most common options and options for ps commands. You can select the options as needed.

The above explains how to use the ps command in the linux Process view. Next we will explain the command who to view the System user information.

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.