Detailed explanation of ps command usage in Linux system

        The ps command is a command used in the Linux system to view the status of the currently running process. It provides many options and parameters for displaying different types of process information. The following is a detailed explanation of the common options and usage of the ps command:

1. Basic usage of ps command

  • ps: Displays a list of processes belonging to the current user in the current terminal session.
  • ps -ef: Displays a list of all processes on the system, including those of other users.
  • ps -aux: Display detailed process information, including CPU and memory usage, etc.

2. Commonly used ps command options

  • -e option: Show all processes, not just those of the current terminal session. This is useful for viewing a process list of the entire system.
  • -f option: Display process information in full format. The full format shows more columns, including parent process ID (PPID), process status, CPU usage (%CPU), memory usage (%MEM), etc.
  • -l option: Display process information in long format. The long format shows more information, such as the process command line, process state (S), session ID (SID) of the process, etc.
  • -u option: Display process information related to the specified user. The displayed list of processes can be limited by specifying a user name.
  • -p option: Display the process information of the specified process ID. The details of a specific process can be viewed by specifying the PID.
  • -o option: Customize the output format. Use this option to specify which columns to display and how to sort them. For example, ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem will display the process ID, parent process ID, command line, memory usage and CPU usage, sorted by memory usage in descending order .

3. Examples of commonly used ps commands

  • ps -ef | grep <process name>: Find the process with the specified process name.
  • ps -ef | grep -v grep | grep <user>: Find the processes of the specified user.
  • ps -ef --forest: Display processes and their parent processes in a tree structure.
  • ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head: Sort and display the information of the first few processes by memory usage.

4. For more options and usage of the ps command, please refer to the help documentation of the ps command

  • man ps: View the man page for the ps command.
  • ps --help: Display brief help information for the ps command.

5. Explain the output results

This command outputs all processes in the system that start with the python keyword. The explanation is as follows:

  • The process output in the first line is started by the /usr/sbin/tuned command. This is a system tuning tool that automatically adjusts system parameters to improve performance based on system configuration and requirements. The process ID (PID) of this process is 921, and the parent process ID (PPID) is 1, which is the init process.
  • The process output on the second line is started by the main_5001.py script. This is a Python script, run by the Python 3 interpreter. The PID of this process is 1012, and the PPID is 1, which is the init process.

In summary, the process output in the first line is part of the system tuning tool, while the process output in the second line is an instance of a Python script.

Parameter specific explanation:

  • root: This is the owner username of the process, indicating that both processes are running as the root user.
  • 921 and 1012: This is the Process ID (PID) that uniquely identifies each running process.
  • 1: This is the ID (PPID) of the parent process, which means that the parent process of these two processes is the init process. The init process is the ancestor process of all processes.
  • 0: This is the priority of the process, meaning that neither process has an explicit priority assigned.
  • May 14 and July 01: These are the start times of the process, indicating that the process started on May 14 and July 01, respectively.
  • ?: This is the TTY (terminal) information of the process, indicating that the two processes are not associated with any terminal.
  • 00:08:22 and 00:00:01: This is the running time of the process, indicating that the process has been running for 8 hours, 22 minutes and 1 second, respectively.
  • /usr/bin/python2 and python3: This is the executable file path of the process, indicating that the first process is running using the Python 2 interpreter and the second process is running using the Python 3 interpreter.
  • -Es /usr/sbin/tuned -l -P and main_5001.py: These are the command line parameters and parameter values ​​of the process, respectively indicating that the first process is a system tuning tool running with these parameters, and the second process is The main_5001.py script run with this parameter value.

Guess you like

Origin blog.csdn.net/weixin_44799217/article/details/131715745