Linux ps command usage

Source: Internet
Author: User

PS is the most commonly used and very powerful process view command in Linux

1. PS Overview

The two commands described above are used to view the current system user situation. The following describes the process situation, which 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

It is also a very powerful process viewing command. You can use this command to determine which processes are running and running, whether the processes are completed,

Whether the process is dead, which processes occupy excessive resources, and so on. 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 have standard input/output settings such as the screen keyboard.

If you need to detect the situation, you can use the ps command.

The syntax of this command is as follows:

PS [Option]

The following describes the Command Options:

-E: displays all processes.

-F full format.

-H does not display the title.

-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 any control 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.

The "-" character is used to reverse the direction of the specified key.

PIDs only lists the values marked as "8 then" and separated by commas. The process list must be in the last option of the command line parameter

A space 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 by number in ascending order or dictionary order. For example, 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

The internal value used is not only used for pseudo values in some output formats. The sorting Key List is shown in Table 4-3.

Table 4-3 sorting Key List

Short format
Long format
Description

C
CMD
Simple executable name

C
Cmdline
Complete command line

F
Flags
Long MODE flag

G
Pgrp
Group ID of the process

G
Tpgid
Control tty Process Group ID

J
Cutime
Cumulative user time

J
Cstime
Accumulative system time

K
Utime
User time

K
Stime
System time

M
Min_flt
Number of secondary page errors

M
Maj_flt
Number of major 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
Resident page

S
Size
Memory size (kilobytes)

S
Share
Number of shared pages

T
Tty
Tty secondary device number

T
Start_time
Process start time

U
UID
UID

U
User
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.

You need to know 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.

[Example 20] 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 four parts: PID (process ID), tty (terminal name), and time (process execution time)

Command (command line input of the process ).

You can 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 the process is the user's login shell, so for a login user, there is a short horizontal line

There is only one process. You can also see two options: % CPU and % mem. The former indicates the percentage of CPU time and total time occupied by the process, and the latter indicates the process.

The percentage of memory used and total memory.

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.

The X option is required. Use the X option to view all processes.

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.