One day a shell command Linux good housekeeper-process-ps command detailed _linux Shell

Source: Internet
Author: User
Tags memory usage sessions system log

Small knowledge (take PS as an example):

View command path which PS
command to help PS--help
Command Complete manual: Man PS

Description

The PS full name is the process status (process state), and he is the one who provides information about the processes.

The PS command is used to report the current system's process state. Can be used with the kill command at any time to interrupt, delete unnecessary programs. The PS command is the most basic and powerful process view command that can be used to determine which processes are running and running, whether the process is over, if the process is dead, what processes are consuming too many resources, and so on, and most of the information can be obtained by executing the command.

A description of the knowledge

We often see that there are three types of arguments to the shell command, and at first I figured out what the special meaning of a single dash and a double dash was, which was the problem of a version evolution.

3 types of command-line parameters that are common in Linux systems (for example, PS):
Parameters of Unix type, preceded by a dash such as: ps-e
BSD-type parameters, preceded by a dash such as: PS A
GNU long parameters, preceded by a double line such as: PS--deselect

Therefore, Ps–a and PS a query results will be different

Common examples

$ps

As shown in figure:

Explanation: By default, the PS command displays only those processes that belong to the current user and are running in the current terminal. Default PS, only the bash and PS are run

$ps –ef

As shown in figure:

Explanation:
The UID owns the user of the process
PID process ID
PPID The parent process PID
Process Utilization of the lifetime of the stime process
The system time at the start of the procedure
TTY process-owned terminal
time  Run the process cumulative CPU time
CMD START process name
Help document
This time I'm using Redhat's--help, and getting PS helps is divided into five categories:
Simple selection  Easy options

Simple Selection *********
-A All processes all threads
-N Negate selection Ignore selection
-a all W/tty except session leaders displays all processes for a terminal, in addition to conversation leads
-D All except session leaders displays all processes, but omits all sessions leads (utility)
-E All Processes
T All processes on this terminal
A all w/tty, including and other users
G OBSOLETE--do don't use
R only Running processes
X processes w/o controlling ttys

Selection by list option

Selection by list *********
-C by command name
-G by Real Group ID (supports names)
-U by Real user ID (supports names)
-G by Sessions OR by effective group name
-P by Process ID
-S processes in the sessions given
-T by TTY
-U by effective user ID (supports names)
U processes for specified users
T by TTY

Output format formatted

Output Format **********
-o,o user-defined can enter its own parameters
-F Full
-j,j Job Control
S signal
-o,o preloaded
-O v virtual memory
-l,l Long
U user-oriented
-F Extra full
X Registers

Long options length operation type

Long Options ***********
--group--user--pid--cols--ppid
--group--user--sid--rows--info
--cumulative--format--deselect
--sort--tty--forest--version
--heading--no-heading--context

Misc Options Other option

Misc Options *********

-v,v Show version L list format codes F ASCII Art Forest
-m,m,-l,-t,h threads S Children in sum-y change-l format
-m,z Security Data C True command Name-c scheduling class
-w,w wide output n numeric wchan,uid-h process hierarchy


Instance (from Man PS)

1. View the standard parameters for each process of the system (to see every process on the system using standard syntax)

Copy Code code as follows:

$ps-E
$ps-ef
$ps-ef
$ps –ely

2. View the BSD (system name) parameters for each process of the system (to see every process on the system using BSD syntax)

Copy Code code as follows:

$ps Ax
$ps Axu

3. Print process tree (to print a process trees)

Copy Code code as follows:

$ps-ejh
$ps AXJF

4. Information about the printing thread

Copy Code code as follows:

$ps-elf
$ps AXMS

5. Get Security information

Copy Code code as follows:

$ps-eo Euser,ruser,suser,fuser,f,comm,label
$ps Axz
$ps –em

6. To see how each process runs in the user's root directory (real and valid ID) format

$ps-u root-u root U

7. View user-defined formats (to see every process with a user-defined format)

Copy Code code as follows:

$ps-eo Pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
$ps Axo Stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
$ps-eopid,tt,user,fname,tmout,f,wchan

8. Print only the process ID of the system log (print only the processes IDs of SYSLOGD)

$ps-C Syslogd-o pid=

9. Only print pid=42 's name (print only the name of PID 42)

$PS-P 42-o comm=

10. Practical to (7) as an example, in accordance with the custom format to look at CPU information

$ps-eo Comm,pcpu | Head

Appendix:-0 Parameter catalogue

Parameters Describe
Pcpu CPU occupancy Rate
Pid Process ID
Ppid Parent Process ID
Pmem Memory usage
Comm Executable file
Cmd Easy commands (Simple command)
User The user who started the process
Nice Priority (niceness)
Time Cumulative CPU Time
ETime Cumulative time after process startup
Tty Current terminal process
Euid Valid User ID
Stat Process status

PS syntax

PS (option)

PS Options

-A: Displays the programs executed under all terminals, except for the stage-working leader.
A: Display all procedures under the current terminal, including other user's procedures.
-A: Displays all programs.
-C: Displays the CLS and PRI fields.
C: When the program is listed, the actual instruction name for each program is displayed, without the path, option or indication of the resident service.
-c< directive Name: Specifies the name of the execution instruction and lists the status of the program for the instruction.
-D: Programs that display all programs, but do not include stage job leaders.
-e: This option has the same effect as the specified "A" option.
E: Displays the environment variables used by each program when the program is listed.
-F: Displays Uid,ppip,c and Stime fields.
F: Displays the tree structure with ASCII characters, expressing the interrelationship between programs.
-g< Group name: This option has the same effect as the specified "-G" option, and can also be specified using the name of the stage job leader.
G: Show all the procedures under the current terminals, including the group leader's program.
-g< Group Identification Code: Lists the status of the programs that belong to the group, or it can be specified by using the group name.
H: The title column is not displayed.
-H: Displays a tree structure that represents the interrelationships between programs.
-j or J: Displays the program status in a work-controlled format.
-L or L: Displays the program status in a detailed format.
L: The relevant information of the row position.
-M or M: all threads are displayed.
N: A number that represents the user and Wchan fields.
-N: Displays all programs in addition to the programs under the PS instruction terminal.
-p< Program Identification Code: Specifies the program identifier and lists the status of the program.
p< Program Identification code: This option has the same effect as the specified "-P" option, and only slightly differs in the list format.
R: Only the current terminal is in the implementation of the program.
-s< Stage Assignment: The program identification code for the specified stage job, and lists the status of the procedure under which the operation is subordinate.
S: Use the program signal format to display the program status.
S: When the program is listed, it includes the interrupted subroutine data.
-t< Terminal Number: Specifies the terminal number, and lists the status of the program belonging to the terminal.
t< Terminal number: This option has the same effect as the specified "-t" option and only slightly differs in the list format.
-T: Displays all programs under the current terminal.
-u< User identification code: This option has the same effect as the specified "-u" option.
U: Displays program status in a user-oriented format.
-u< user Identification Code: Lists the status of programs that belong to that user, or you can specify them by using the user name.
u< User name: Lists the status of the program that belongs to the user.
V: Use virtual memory format to display program status.
-V or V: Displays version information.
-W or W: Use a wide format to display program status.
X: All programs are displayed and are not differentiated by terminals.
X: Displays program status using Legacy Linux i386 login format.
-y: When used with the option "-L", the f (flag) field is not displayed and the addr field is replaced with an RSS field.
-< Program Identification code: This option has the same effect as the specified "P" option.
--cols<: Sets the maximum number of characters per column.
--columns< per column: This option has the same effect as the specified "--cols" option.
--cumulative: This option has the same effect as the specified "S" option.
--deselect: This option has the same effect as the specified "-N" option.
--forest: This option has the same effect as the specified "F" option.
--headers: Displays the title column repeatedly.
--help: Online Help.
--info: Displays the wrong information.
--lines< Display Columns: Sets the number of columns to display the screen.
--no-headers: This option has the same effect as the specified "H" option, and only slightly differs in the list format.
--group< Group name: This option has the same effect as the specified "-G" option.
--group< Group Identification code: This option has the same effect as the specified "-G" option.
--pid< Program Identification code: This option has the same effect as the specified "-P" option.
--rows< Display columns: This option has the same effect as the specified "--lines" option.
--sid< Phase job: This option has the same effect as the specified "-S" option.
--tty< Terminal number: This option has the same effect as the specified "-t" option.
--user< User name: This option has the same effect as the specified "-u" option.
--user< User identification code: This option has the same effect as the specified "-u" option.
--version: This option has the same effect as the specified "-V" option.
--widty< per column: This option has the same effect as the specified "-cols" option.

Because the PS command can support a very large number of system types, so the options are outrageous!

Related Article

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.