Summary of knowledge points of Linux ps and pstree commands

  • 2021-07-22 12:20:39
  • OfStack

The ps command in Linux is the abbreviation of Process Status. The ps command is used to list those processes currently running on the system. The ps command lists a snapshot of the current processes, which are the processes at the moment when the ps command was executed. If you want to dynamically display process information, you can use the top command.

To monitor and control the process, we must first understand the current process, that is, we need to view the current process, and ps command is the most basic and very powerful process view command. Use this command to determine which processes are running and in what state they are running, whether the process is finished, whether the process is dead, which processes are using too many resources, and so on. In short, most of the information can be obtained by executing this command.

ps provides us with a single view of the process, and the view results provided by it are not dynamic and continuous; If you want to monitor process time, you should use top tool.

The kill command is used to kill processes.

1. View all processes


ps -eF

-e: Select all processes.
-F: Extra full format.

PSR (Processor) displays the CPU where the process is located.

2. View all processes (including threads)


ps -eLF
-e: Select all processes.
-L: Show threads, possibly with LWP and NLWP columns.
-F: Extra full format.

LWP (Low Weight Process), which shows the thread number TID. For the Linux kernel, there is no difference between thread and process management. For users, a process may contain multiple threads. If PID and LWP are the same, the thread is the main thread of the process.

3. Customize Format View


ps -eLo pid,lwp,nlwp,sched,pri,psr,args

-e: Select all processes.
-L: Show threads, possibly with LWP and NLWP columns.
-o: User-defined format.

You can view the parameters you want to view, such as scheduling policy, priority, and so on.

4. pstree

View processes/threads in a tree format using the pstree command.


pstree -p

-p: Show PIDs.

For details on how to use ps and pstree, use the man command.

The above is all the relevant knowledge points of this site. Thank you for your study and support of this site.


Related articles: