Detailed analysis of Linux operating system PS commands

Source: Internet
Author: User

To monitor and control processes in the system, use the ps command to meet your requirements.

/Bin/PS

PS is the state of instantaneous travel, not dynamically consecutive; if you want to monitor the process running time, you should use the top tool.

Kill is used to kill a process.

================== PS parameter description ================================== ======

L long format output;

U displays processes in the username and start time order;

J. display processes in the task format;

F process is displayed in a tree format;

A. display all processes of all users (including other users );

X displays the process of the uncontrolled terminal;

R: displays running processes;

WW to avoid detailed parameter truncation;


-A: list all the itineraries.
-W display widening can display more information
-Au displays more detailed information
-Aux: Show All itineraries containing other users

-E: displays all processes and environment variables.
-F full format
-H: No title is displayed.
-L long format
-W width output
A Display All processes on the terminal, including those of other users
R Only processes in the running state are displayed.
X Show no terminal processes under control

Our common options are combination of aux or lax, and the application of parameter F.

O [+ |-] K1 [, [+ |-] K2 [,…] The process list is displayed in the multi-level sorting order specified by the shortcut keys in short keys, K1, and K2.
The default sequence is specified for different PS formats. these default sequence can be overwritten by user-specified. here, the "+" character is optional, and the "-" character is used to reverse the specified key direction.
PIDs lists only process identifiers separated by commas (,). The process list must be followed by the last option of the command line parameter. spaces cannot be inserted in the list. For example, PS-F1.

The following describes the long command line options. These options start:
-- Sort X [+ |-] Key [, [+ |-] Key [,…] Select a multiple keys from the sort keys segment. the "+" character is optional, because the default direction is in ascending order of numbers or dictionary order. for example, PS-Jax-Sort = uid ,-

Ppid, + PID.
-- Help: displays help information.
-- Version: displays the local version of the command.

The sort key is mentioned in the preceding option description. Next, we will further describe the sort key. note that the land use value in the sorting operation is the internal value of the PS application, not only the pseudo value in some output formats. the following table lists the sort keys.

=============== Sort Key List ================================== =


C cmd Executable simple name
C branch line Complete command line
F flags Long MODE flag
G pgrp Process location group ID
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 error locations
M maj_flt Number of Key page error locations
N cmin_flt cumulative secondary page Error
N cmaj_flt accumulative Key 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 (kilobytes)
S share Number of shared page locations
T tty Tty secondary device number
T start_time process start time
U uid UID
U user User Name
V vsize Total number of local virtual memory (bytes)
Y priority kernel scheduling priority

====================== PS aux or lax output ==========

2. Explanation of PS aux or lax output

Au (x) output format:
User PID % CPU % mem vsz RSS tty stat Start Time Command

User: process owner
PID: process ID

% CPU: CPU usage
% Mem: memory usage
Vsz: Virtual Memory Used
RSS: memory used

TTY: the secondary device Number of the terminal (minor device Number of TTY)

Stat: Process status:

Start: the start time of the process;
Time: the CPU consumption time of the process;
Command: command name and parameters;

======================= Process stat status ==============================

D. The sleep state that cannot be interrupted (usually the IO process );
R is running, In the disconnected queue;
S is in sleep or static state;
T stop or be tracked, pause execution;
W enters the memory switch (it is invalid from kernel 2.6 );
X dead processes;
Z botnets do not exist but cannot be eliminated temporarily;

W: insufficient memory paging allocable
Wchan is waiting for Process resources;

<: High-priority process
N: low-priority process
L: memory is allocated by PAGE and locked in the memory (real-time system or memory a I/O). That is, some pages are locked into the memory.

S process leader (with sub-processes under it );
L multi-process (using clone_thread, similar to nptl pthreads );
+ Process group in the background;

===================== Kill terminate a process ============================== ====

Kill Process Termination

There are more than a dozen methods to control processes. Below are some common methods:

Kill-stop [pid]
Send sigstop (17,19, 23) to stop a process without killing it.

Kill-cont [pid]
Send sigcont (, 25) to start a stopped process again.

Kill-kill [pid]
Send sigkill (9) to force the process to stop immediately without cleaning.

Kill-9-1
Terminate all processes you have.

The sigkill and sigstop signals cannot be captured, blocked, or ignored. However, other signals are acceptable. So this is your weapon.

======================== Example ================================ =

$ PS
PID tty Time Command
5800 ttyp0 00:00:00 bash
5835 ttyp0 00:00:00 PS
As you can see, projects are divided into four items: 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 that the process is logged on to the shell by the user, so for a login user, there is only one process with a transient line. you can also see two options: % CPU and % mem. The former indicates the CPU time occupied by the process.

Percentage of total time, which indicates the percentage of memory occupied by the process and total memory.
In this case, we can see all the processes that control terminals. Of course, we still haven't observed other processes that do not control terminals. Therefore, we need to use the X option. you can use the X option to view all processes in the process.

1) pS A shows all programs under the current terminal, including those of other users.
2) PS-A shows all programs.
3) when listing programs in ps c, the real command name of each program is displayed without the path, parameter or resident service identifier.
4) the effect of this parameter is the same as that of the specified "A" parameter.
5) when listing programs, PS e displays the environment variables used by each program.
6) pS F uses ASCII characters to display the tree structure and express the relationship between programs.
7) the PS-H tree structure is displayed, indicating the relationship between programs.
8) PS-n shows all programs, except the programs under the ps command terminal.
9) pS displays the program status in the program signal format.
10) when listing programs in PS, it includes interrupted subroutines.
11) PS-T <terminal number> specifies the terminal number and lists the status of programs belonging to the terminal.
12) pS U displays the program status in user-based format.
13) pS X shows all programs, which are not distinguished by terminals.

The most common method is PS-Aux, which is then directed to grep with the pipeline symbol to find a specific process and then operate on the specific process.

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.