[Comprehensive explanation of Linux commands] 164. In-depth understanding of the ps command in Linux: Process status reporting tool

ps command

Additional information

psThe command is used to report the process status of the current system. You can use killcommands to interrupt and delete unnecessary programs at any time. psThe command is the most basic but also very powerful process viewing command. You can use this command to determine which processes are running and running status, whether the process has ended, whether the process is zombie, which processes occupy too many resources, etc. In short, Some information can be obtained by executing this command.

grammar

ps(选项)

Options

  • -a: Displays the programs executed under all terminals, except the stage job leader.
  • a: Display all programs under the current terminal, including programs of other users.
  • -A: Display all programs.
  • -c: Display CLS and PRI fields.
  • c: When listing programs, display the actual command name of each program without including the path, options, or identification of resident services.
  • -C<指令名称>: Specify the name of the execution instruction and list the status of the program that executes the instruction.
  • -d: Shows all programs except the program of the stage job leader.
  • -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: Display UID, PPIP, C and STIME fields.
  • f: Use ASCII characters to display a tree structure and 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 stage job leader.
  • g: Display all programs under the current terminal, including the group leader's programs.
  • -G<群组识别码>: Lists the status of programs belonging to this group, which can also be specified using the group name.
  • h: Does not display the title bar.
  • H: Displays a tree structure, indicating the relationship between programs.
  • jOr j: Display program status in job control format.
  • lOr l: Use a detailed format to display program status.
  • L: List the relevant information of the field.
  • mOr m: display all execution threads.
  • n: Use numbers to represent USER and WCHAN fields.
  • N: Display all programs, except programs under the terminal that execute the ps command.
  • -p<程序识别码>: Specify the program identification code and list the status of the program.
  • p<程序识别码>: The effect of this option is the same as specifying the "-p" option, with only slight differences in the list format.
  • r: List only the programs currently being executed by the terminal.
  • -s<阶段作业>: Specify the program identification code of the stage operation, and list the status of the programs belonging to the stage operation.
  • s: Use the program signal format to display the program status.
  • S: When listing programs, include interrupted subroutine information.
  • -t<终端机编号>: Specify a terminal number and list the status of programs belonging to that terminal.
  • t<终端机编号>: The effect of this option is the same as specifying the "-t" option, with only slight differences in the list format.
  • T: Display all programs under the current terminal.
  • -u<用户识别码>: This option has the same effect as specifying the "-U" option.
  • u: Display program status in user-oriented format.
  • -U<用户识别码>: Lists the status of programs belonging to this user, which can also be specified using the user name.
  • U<用户名称>: Lists the status of programs belonging to this user.
  • v: Display program status in virtual memory format.
  • VOr V: Display version information.
  • wOr w: Use a broad format to display program status.
  • x: Display all programs, not distinguished by terminal.
  • X: Use the old Linux i386 login format to display program status.
  • -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<每列字符数>: Set 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: Display the title bar repeatedly.
  • --help: Online help.
  • --info: Display troubleshooting information.
  • --lines<显示列数>: Set the number of columns in the display screen.
  • --no-headers: The effect of this option is the same as specifying the "h" option, with only slight differences in the 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.

Example

  • View the PID, name and CPU usage of the process:

    ps axo pid,comm,pcpu
    
  • Sort processes by memory resource usage:

    ps aux | sort -rnk 4
    
  • Sort processes by CPU resource usage:

    ps aux | sort -nk 3
    
  • Display all process information:

    ps -A
    
  • Display specified user information:

    ps -u root
    
  • Check the number of threads:

    ps -efL
    
  • View processes and sort them by memory usage:

    ps -e -o "%C : %p :%z : %a" | sort -k5 -nr
    
  • Display all process information, along with the command line:

    ps -ef
    
  • Commonly used combinations of ps and grep to find specific processes:

    ps -ef | grep ssh
    
  • Search for processes by name or command:

    ps -C nginx
    
  • CPU or memory sorting, descending order:

    ps aux --sort=-pcpu,+pmem
    
  • Display the hierarchical relationship of processes in a tree style:

    ps -f --forest -C nginx
    
  • Display the child processes of a parent process:

    ps -o pid,uname,comm -C nginx
    
  • Redefine tags:

    ps -e -o pid,uname=USERNAME,pcpu=CPU_USAGE,pmem,comm
    
  • Show how long a process has been running:

    ps -e -o pid,comm,etime
    
  • View named process details:

    ps -aux | grep named
    
  • Get the service name by process id:

    ps -o command -p 91730 | sed -n 2p
    
  • List the PID and related information currently belonging to you for this login:

    ps -l
    
  • List all programs currently in memory:

    ps aux
    
  • Find out the PID numbers associated cronwith syslogthese two services:

    ps aux | egrep '(cron|syslog)'
    
  • Display all processes and output to ps001.txta file:

    ps -aux > ps001.txt
    
  • Output the specified fields:

Learn from scratchpython

[Learn python from scratch] 92. Use Python’s requests library to send HTTP requests and process responses
[Learn python from scratch] 91. Use decorators and dictionaries to manage request paths in a simple web application
[Learn python from scratch] 93. Use dictionary management Request path
[Learn python from scratch] 89. Use WSGI to build a simple and efficient Web server
[Learn python from scratch] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from scratch] 87. Manually build an HTTP server in Python Implementation and multi-threaded concurrent processing
[Learn python from scratch] 86. In-depth understanding of the HTTP protocol and its role in browser and server communication
[Learn python from scratch] 85. Application of parallel computing technology in Python process pool
[Learn python from scratch] ] 84. In-depth understanding of threads and processes
[Learn python from scratch] 83. Python multi-process programming and the use of process pools
[Learn python from scratch] 82. Chat program implementation based on multi-threading
[Learn python from scratch] 81. Python more Application of thread communication and queue
[Learn python from scratch] 80. Thread access to global variables and thread safety issues
[Learn python from scratch] 79. Thread access to global variables and thread safety issues
[Learn python from scratch] 78. File download case
[ Learn python from scratch] 77. TCP server programming and precautions
[learn python from scratch] 76. Server and client: key components of network communication
[learn python from scratch] 75. TCP protocol: reliable connection-oriented transmission layer communication protocol
[Learn python from scratch] 74. UDP network program: Detailed explanation of port issues and binding information
[Learn python from scratch] 73. UDP network program - sending data
[Learn python from scratch] 72. In-depth understanding of Socket communication and creation of sockets Method
[Learn python from scratch] 71. Network ports and their functions
[Learn python from scratch] 70. Network communication methods and their applications: from direct communication to routers to connect multiple networks
[Learn python from scratch] 69. Network communication and IP address classification analysis
[Learn python from scratch] 68. Greedy and non-greedy modes in Python regular expressions
[Learn python from scratch] 67. The re module in Python: regular replacement and advanced matching technology
[Learn python from scratch] 66 .In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[Learn python from scratch] 65. Detailed explanation of Python regular expression modifiers and their applications
[Learn python from scratch] 64. The re.compile method in Python regular expressions Detailed explanation of usage
[Learn python from scratch] 63. Introduction to the re.Match class and its attributes and methods in regular expressions
[Learn python from scratch] 62. Python regular expressions: a powerful string matching tool
[Learn python from scratch] 61. Detailed explanation and application examples of property attributes in Python
[Learn python from scratch] 60. Exploration generator: a flexible tool for iteration
[Learn python from scratch] 59. Iterator: An efficient tool for optimizing data traversal
[Learn python from scratch] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from scratch] 57. Use the with keyword in Python to correctly close resources
[Learn python from scratch] 56. The importance and application of exception handling in programming
[Learn python from scratch] 55. Serialization and sum in Python Deserialization, application of JSON and pickle modules
[Learn python from scratch] 54. Writing data in memory
[Learn python from scratch] 53. CSV files and Python’s CSV module
[Learn python from scratch] 52. Reading and writing files - Python file operation guide
[Learn python from scratch] 51. Opening and closing files and their applications in Python
[Learn python from scratch] 49. Object-related built-in functions in Python and their usage
[Learn python from scratch] 48 .Detailed explanation of inheritance and multiple inheritance in Python
[Learn python from scratch] 47. The concept and basic use of inheritance in object-oriented programming
[Learn python from scratch] 46. Analysis of __new__ and __init__ methods and singletons in Python Design Patterns
[Learn python from scratch] 45. Class methods and static methods in Python
[Learn python from scratch] 44. Private properties and methods in object-oriented programming
[Learn python from scratch] 43. Examples in Python object-oriented programming Properties and class attributes
[Learn python from scratch] 42. Built-in properties and methods in Python
[Learn python from scratch] 41. python magic method (2)
[Learn python from scratch] 40. python magic method (1)
[Learn python from scratch] 39. Basic object-oriented syntax and application examples
[Learn python from scratch] 38. How to use and import Python packages
[Learn python from scratch] 37. The use and precautions of Python custom modules
[Learn python from scratch] Learn python] 36. Methods and techniques of using pip for third-party package management in Python
[Learn python from scratch] 35. Common Python system modules and their usage
[Learn python from scratch] 34. Detailed explanation of the import and use of Python modules
[ Learn python from scratch] 33. The role of decorators (2)
[Learn python from scratch] 32. The role of decorators (1)
[Learn python from scratch] 31. In-depth understanding of higher-order functions and closures in Python
[From Learn python from scratch】30. In-depth understanding of recursive functions and anonymous functions
【learn python from scratch】29. "Detailed explanation of function parameters" - understand the different uses of Python function parameters
【learn python from scratch】28. Local variables and global variables in Python Variables
[Learn python from scratch] 27. The use of Python functions and nested calls
[Learn python from scratch] 25. Functions: a tool to improve the efficiency of code writing
[Learn python from scratch] 24. String operations and traversal methods in Python
[Learn python from scratch] 23. How to use sets (set) and common operations in Python
[Learn python from scratch] 22. Add, delete, modify, and query dictionary variables in Python
[Learn python from scratch] 21. Python tuples and dictionaries
[Learn python from scratch] 20. Python list operation skills and examples
[Learn python from scratch] 19. Applications of looping through lists and list nesting
[Learn python from scratch] 18. Detailed explanation of the basic operations of Python lists (1)
[From Learning python from scratch】 17. The format method of Python strings (2)
【Learning python from scratch】 16. The format method of Python strings (1)
【Learning python from scratch】 15. In-depth understanding of strings and character set encoding
【From Learning python from scratch】14. Common operations on Python strings (2)
【Learning python from scratch】13. Common operations on Python strings (1)
【Learning python from scratch】12. Python string operations and applications
【Learning python from scratch】 11. Python loop statements and control flow
[Learn python from scratch] 10. Detailed explanation of Python conditional statements and if nesting
[Learn python from scratch] 09. Conditional judgment statements in Python
[Learn python from scratch] 08. Python understands bit operations operator, operator priority
[Learn python from scratch] 07. Detailed explanation of Python operators: assignment, comparison and logical operators
[Learn python from scratch] 06. Use arithmetic operators in Python for calculations and string concatenation
[Learn from scratch] python ] 05. Output and input in Python
[Learn python from scratch] 04. Basics of Python programming: variables, data types and identifiers
[Learn python from scratch] 03. Python interactive programming and detailed explanation of comments
[Learn python from scratch] 02. Introduction to development tools
[Learn python from scratch] 01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/132977673