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 view processes and threads under Linux

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains "how to view processes and threads under Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to view processes and threads under Linux".

Three ways to check the number of threads in Linux

1. Top-H

The manual says:-H: Threads toggle

Add this option to start the top,top line to display a thread. Otherwise, it displays a process on one line.

2 、 ps xH

The manual says: H Show threads as if they were processes

This allows you to see all the threads that exist.

3. Ps-mp

The manual says: m Show threads after processes

This allows you to see the number of threads started by a process.

View the process

1. Top command

Top command to view the resource status of the system

Load average says how many processes have attempted to monopolize CPU in the past

Zombie process: not an exception. A process is full of zombies during the last period of time from creation to completion. What is left in memory for the parent process to fetch is a zombie. Any program has a zombie state, it takes up a little memory resources, it is just the appearance and there is no need to be afraid. If there is a problem with the program and there is a chance to encounter it, the simple and effective way to solve a large number of zombies is to start over. Kill is a stop mode with no effect: different from the sleep process, sleep actively abandons cpu, while stop passively abandons cpu. For example, a single-step trace, a stop (paused) process cannot return to the running state by itself.

Cpu states:

Nice: percentage of yield irq: interrupt processing occupancy

Idle: percentage of footprint iowait: input / output wait (if it is large enough to indicate that there is a bottleneck in the external memory, you need to upgrade the hard disk (SCSI))

Mem: memory condition

Design idea: saving resources and not using them is a waste. For example, after adding memory, the free value will remain the same, and the buffing value will increase. Determine whether there is enough physical memory and look at the usage status of the swap partition.

Interactive commands:

[Space] refresh the display immediately

[h] display the help screen

[K] kill a process. You will be prompted to enter the process ID and the signal to send to it. A general termination process can use a 15 signal; if it does not end properly, use signal 9 to force the process to end. The default value is signal 15. This command is blocked in safe mode.

[n] change the number of processes displayed. You will be prompted to enter the quantity.

[U] sort by user.

[M] sort by memory usage.

[O] [O] change the order in which items are displayed.

[P] sort according to the percentage of CPU usage.

[t] sort by time / cumulative time.

[Ctrl+L] erase and rewrite the screen.

[Q] exit the program.

[r] rearrange the priority of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value to be set. Entering a positive value lowers the priority, otherwise it gives the process a higher priority. The default value is 10.

[s] switch to cumulative mode.

[s] change the delay between refreshes. The user will be prompted to enter a new time in s. If there is a decimal, it is converted to m s. Enter a value of 0 and the system will continue to refresh, with a default value of 5 s. It should be noted that if you set too little time, it is likely to cause continuous refresh, so that it is too late to see the display at all, and the system load will be greatly increased.

The meaning of the abbreviation:

PID ID of each process

User name of the owner of the USER process

PRI priority of each process

The value of each priority of NI

The code size of the SIZE process plus the data size plus the total stack space size, which is the total amount of physical memory occupied by the KB RSS process in KB

The amount of shared memory used by SHARE processes

Status of the STAT process. Where S stands for dormant state; D for uninterruptible dormant state; R for running state; Z for dead state; T for stop or tracking state

% percentage of CPU time and total time spent by the CPU process since the last refresh

% physical memory occupied by MEM processes as a percentage of total memory

Total CPU time spent by the TIME process since it was started

CPU CPU identification

Command name of the COMMAND process

2. Ps command

Ps looks at the active processes of the current user. If you add parameters, you can display more information, such as-a, and show the processes of all users.

Ps ax: the Tty value is "?" It is a daemon called deamon without terminal. Most system services are this process, and kernel state processes are invisible.

Ps axf: look at the process tree and click on the real process list in a tree way. Init is process 1, and all the processes in the system are derived from it and cannot be killed.

Ps axm: threads are listed. Under linux, processes and threads are unified, and they are two ways of lightweight processes.

Ps axu: displays the detailed status of the process.

Vsz: how much physical memory is consumed by this process?

Rss: how much resident memory is requested?

View thread

In fact, linux has no threads and is imitated by processes.

1. Ps-ef f

Use a tree to show processes and threads. For example, I want to find out how many processes / threads there are in proftp. You can use the

$ps-ef f | grep proftpd

Nobody 23117 1 0 Dec23? S 0:00 proftpd: (accepting connections)

Jack 23121 23117 0 Dec23? S 7:57\ _ proftpd: jack-ftpsrv: IDLE

Jack 28944 23117 0 Dec23? S 4:56\ _ proftpd: jack-ftpsrv: IDLE

So you can see that there are two threads hanging under the proftpd process.

Under Linux, it seems that because there is no real thread, it is simulated by a process, and one is a worker thread, so there should be only one thread open by the real program.

2. Pstree-c can also achieve the same effect.

$pstree-c | grep proftpd

| |-proftpd-+-proftpd |

| | `- proftpd |

3. Cat / proc/$ {pid} / status

You can see the general situation.

4. Pstack

Some systems can use this thing to view the stack of all threads

How do I view the memory footprint of each thread in a process?

You can only see the process with ps aux. If pthread programming is used in the process, what command can be used to query the thread resources in the process?

Ps aux | grep is the case.

Thank you for your reading, the above is the content of "how to view processes and threads under Linux". After the study of this article, I believe you have a deeper understanding of how to view processes and threads under Linux. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report