View processes and threads in Linux

Source: Internet
Author: User

View processes and threads in Linux

Three methods for viewing the number of threads in Linux

1. top-H
-H: Threads toggle
Add this option to start top, and a thread is displayed in the top row. Otherwise, a process is displayed in one row.
2. ps xH
H Show threads as if they were processes
This allows you to view all existing threads.
3. ps-mp <PID>
M Show threads after processes
In this way, you can view the number of threads started by a process.

View Processes

1. top Command

Top command to view system resource status

Load average indicates how many processes tried to exclusively occupy the CPU in the past period.

Zombie process: no exception. A process is a zombie in the last period from creation to completion. What is left in the memory waiting for the parent process to take is a zombie. Any program is in zombie state. It occupies a little memory and is just a representation, so you don't have to be afraid. If there is a problem with the program, the simple and effective way to solve a large number of botnets is to restart. Kill is a stop mode with no effect: it should be different from the sleep process. sleep will take the initiative to give up the cpu, while stop is passive to give up the cpu, for example, one-step tracking, stop (pause) the process cannot return to the running state on its own.

Cpu states:

Nice: let out percentage irq: used for Interrupt Processing

Idle: Percentage of space occupied iowait: Input and Output wait (if it is large, it indicates there is a bottleneck, You need to upgrade the hard disk (SCSI ))

Mem: memory usage

Design Philosophy: saving resources is a waste. For example, the free value will not change after the memory is added, and the buff value will increase. Check the Usage Status of swap partitions if the physical memory is insufficient.

Interactive command:

[Space] refresh the display now

[H] display the help screen

[K] Kill a process. You will be prompted to enter the process ID and the signal to be sent to it. Generally, 15 signals can be used to terminate a process. If the process cannot end normally, use signal 9 to forcibly end the process. The default value is signal 15. This command is blocked in security mode.

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

[U] is sorted by user.

[M] sort by memory usage.

[O] [O] changes the order of projects displayed.

[P] sort by CPU usage percentage.

[T] sort by time/accumulative time.

[Ctrl + L] erase and override the screen.

[Q] exit the program.

[R] reschedule the priority of a process. The system prompts the user to enter the process PID to be changed and the process priority value to be set. Entering a positive value will lower the priority, and vice versa will give the process a higher priority. The default value is 10.

[S] switch to the accumulative mode.

[S] Change the delay time between two refreshes. The system prompts the user to enter a new time in seconds. If there is a decimal number, it is converted to m s. If the input value is 0, the system will be refreshed continuously. The default value is 5 s. It should be noted that if the setting is too small, it is likely to cause constant refresh, so it is too late to see the display, and the system load will increase significantly.

Abbreviation:

Pid id of each process

USER: USER Name of the process owner

PRI priority for each process

NI value of each priority

SIZE: the code SIZE of a process, the data SIZE, and the total SIZE of the stack space. The unit is the total amount of physical memory occupied by the kb rss process. The unit is KB.

Number of shared memory used by the SHARE Process

The status of the STAT process. S indicates the sleep state, D indicates the non-interrupted sleep state, R indicates the running state, Z indicates the frozen state, and T indicates the stopped or tracked state.

% Percentage of CPU time and total time used by the CPU process since the last refresh

% MEM percentage of physical memory occupied by the process in total memory

TIME total cpu time used by the process since it was started

CPU ID

COMMAND name of the COMMAND process

2. ps command

Ps: view the active processes of the current user. If a parameter is added, more information can be displayed, such as-a, showing the processes of all users.


Ps ax: the tty value is "?" It is a daemon process called deamon with no terminal. Most system services are in this process and kernel-State processes cannot be seen.

Ps axf: Look at the process tree. In the tree-like way, the list of actual processes is broken. init is the process No. 1, and all the processes in the system are derived from it.

Ps axm: Lists threads. In linux, processes and threads are unified. They are two lightweight processes.

Ps axu: displays the detailed status of the process.

Vsz: the total amount of physical memory occupied by the process.

Rss: Number of Requests resident memory

View threads

In fact, linux does not have a thread and it is imitated by processes.

1. ps-ef f
Process and thread are displayed in a tree. For example, if you want to find how many processes/Threads proftp currently has, you can use
$ 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
In this way, we can see that there are two threads under the proftpd process.
In Linux, there seems to be no real thread, Which is simulated by a process. One is an auxiliary thread, so there should be only one thread for a real program.

2. pstree-c can achieve the same effect.
$ Pstree-c | grep proftpd
|-Proftpd-+-proftpd
| '-Proftpd

3. cat/proc/$ {pid}/status
You can view the general information.

4. pstack

Some systems can use this to view the stacks of all threads.

How can I check the memory usage of each thread in a process?

Ps aux can only be used to view the process. If pthread is used in the process, what command can be used to query the thread resource occupation in the process?
Ps aux | grep No

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.