Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the ps command in linux

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to use the ps command in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

A little knowledge (take ps as an example):

View the command path which ps

Command help ps-- help

Command complete manual: man ps

Description

The full name of ps is: Process Status (process status), which provides process information.

The ps command is used to report the process status of the current system. You can interrupt and delete unnecessary programs at any time with kill instructions. Ps command is the most basic but also very powerful process view command, which can be used to determine which processes are running and running status, whether the process ends, whether the process is dead, which processes take up too much resources, and so on. In short, most of the information can be obtained by executing the command.

With knowledge explanation

We often see that the shell command has three types of parameters, and at first I wondered what the special meaning of single and double dashes had, which turned out to be a problem left by the evolution of a version.

Three common command line parameters in linux systems (take ps as an example):

A parameter of type Unix, preceded by a dash such as: ps-e

A parameter of type BSD with no dash in front of it, such as ps a

GNU long parameter, preceded by a double dash, such as: ps-- deselect

So, ps-an and ps a query results will be different

Common examples

$ps

As shown in the figure:

Explanation: by default, the ps command displays only processes that belong to the current user and are running in the current terminal. If you default to ps, only bash and ps are running

$ps-ef

As shown in the figure:

Explanation:

UID user who owns the process

ID of the PID process

PPID parent process PID

Processing utilization of the duration of the C process

System time when the STIME process starts

The terminal to which the TTY process belongs

Cumulative CPU time of TIME running process

Name of the CMD startup process

Help documentation

This time I used redhat's-- help, and the help that got ps was divided into five categories:

Simple options for simple selection

* simple selection *

-An all processes all threads

-N negate selection ignores selection

-an all w / tty except session leaders shows all processes of a terminal, except for session leads

-d all except session leaders shows all processes, but omits all session leads (utility)

-e all processes

T all processes on this terminal

An all w/ tty, including other users

G OBSOLETE-- DO NOT USE

R only running processes

X processes w/o controlling ttys

Selection by list list options

* selection by list *

-C by command name

-G by real group ID (supports names)

-U by real user ID (supports names)

-g by session 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 output formatting

* output format *

-o user-defined can enter its own parameters

-f full

-JMagol j job control

S signal

-O preloaded O preloaded

-o v virtual memory

-ldjinl long

U user-oriented

-F extra full

X registers

Long options long 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

Other options for misc options

* misc options *

-VMagne V show version L list format codes f ASCII art forest

H threads S children in sum-y change-l format

-M security data c true command name Z security data c true command name-c scheduling class

-w wide output n numeric WCHAN,UID w 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)

The code is as follows:

$ps-e

$ps-ef

$ps-eF

$ps-ely

two。 View the BSD (system name) parameter (To see every process on the system using BSD syntax) for each process of the system

The code is as follows:

$ps ax

$ps axu

3. Print process Tree (To print a process tree)

The code is as follows:

$ps-ejH

$ps axjf

4. Print information about the thread

The code is as follows:

$ps-eLf

$ps axms

5. Get security information

The code is as follows:

$ps-eo euser,ruser,suser,fuser,f,comm,label

$ps axZ

$ps-eM

6. To view each process running in the user root directory (real and valid ID) format

$ps-U root-u root u

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

The code is 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. Process ID (Print only the process IDs of syslogd) that prints only the Syslog

$ps-C syslogd-o pid=

9. Print only the name of pid=42 (Print only the name of PID 42)

$ps-p 42-o comm=

10. Take (7) as an example to view cpu information in a custom format.

$ps-eo comm,pcpu | head

Attached:-0 parameter directory

Parameter describes pcpuCPU occupancy pid process IDppid parent process IDpmem memory utilization comm executable simple command (simple command) user nice priority (niceness) user startup process time cumulative CPU time after etime process startup tty current terminal process euid valid user IDstat process status

Ps syntax

Ps (option)

Ps option

-a: displays all programs executed under the terminal, except for the phase job leader.

A: displays all programs under the current terminal, including those of other users.

-A: show all programs.

-c: displays the CLS and PRI fields.

C: when programs are listed, the real instruction name of each program is displayed, without the identification of paths, options, or resident services.

-C: specifies the name of the execution instruction and lists the status of the program in which the instruction is executed.

-d: displays all programs, excluding those of phase operation leaders.

-e: this option has the same effect as specifying the "A" option.

E: when listing programs, display the environment variables used by each program.

-f: displays the UID,PPIP,C and STIME fields.

F: display the tree structure with ASCII characters to express the relationship between programs.

-g: this option has the same effect as specifying the "- G" option, and can also be specified using the name of the phase operation leader.

G: displays all programs under the current terminal, including those of group leaders.

-G: lists the status of programs that belong to this group, or you can specify it using the group name.

H: the title column is not displayed.

-H: displays the tree structure, indicating the interrelationship between programs.

-j or j: displays the status of the program in a work-controlled format.

-l or l: displays the status of the program in a detailed format.

L: list the relevant information about the field.

-m or m: displays all threads.

N: USER and WCHAN fields are represented by numbers.

-N: displays all programs except those under the ps instruction terminal.

-p: specify the program identification number and list the status of the program.

P: this option has the same effect as specifying the "- p" option, with only slight differences in list format.

R: list only the programs that are being executed by the current terminal.

-s: specify the program identification code of the phase operation and list the status of the programs belonging to that phase operation.

S: display the status of the program in the format of the program signal.

S: when listing the program, include the interrupted subroutine data.

-t: specify the terminal number and list the status of the programs that belong to the terminal.

T: this option has the same effect as specifying the "- t" option, except for slight differences in list format.

-T: displays all programs under the current terminal.

-u: this option has the same effect as specifying the "- U" option.

U: displays the status of the program in a user-based format.

-U: lists the status of the programs that belong to the user, or you can specify them using the user name.

U: lists the status of programs that belong to this user.

V: displays the status of the program in the format of virtual memory.

-V or V: displays version information.

-w or w: displays the status of the program in a broad format.

X: displays all programs, not distinguished by terminals.

X: displays the status of the program in the old Linux i386 login format.

-y: when used with the option "- l", the F (flag) field is not displayed, and the ADDR field is replaced by the RSS field.

-: this option has the same effect as specifying the "p" option.

-- cols: sets the maximum number of characters per column.

-- columns: this option has the same effect as specifying the "--cols" option.

-- cumulative: this option has the same effect as specifying the "S" option.

-- deselect: this option has the same effect as specifying the "- N" option.

-- forest: this option has the same effect as specifying the "f" option.

-- headers: the title column is displayed repeatedly.

-- help: online help.

-- info: displays troubleshooting information.

-- lines: sets the number of columns in the display screen.

-- no-headers: this option has the same effect as specifying the "h" option, except for slight differences in list format.

-- group: this option has the same effect as specifying the "- G" option.

-- Group: this option has the same effect as specifying the "- G" option.

-- pid: this option has the same effect as specifying the "- p" option.

-- rows: this option has the same effect as specifying the "--lines" option.

-- sid: this option has the same effect as specifying the "- s" option.

-- tty: this option has the same effect as specifying the "- t" option.

-- user: this option has the same effect as specifying the "- U" option.

-- User: this option has the same effect as specifying the "- U" option.

-- version: this option has the same effect as specifying the "- V" option.

-- widty: this option has the same effect as specifying the "- cols" option.

This is the end of the article on "how to use ps commands in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report