three ways to view the number of threads in Linux1, top-h Manual said:-h:threads Toggle plus this option to start a top,top line to display a thread. Otherwise, it displays a process one line. 2, PS XH Manual said: H Show threads as if they were processes so that all existing threads can be viewed. 3, PS-MP <PID> Handbook said: M show threads after processes this allows you to see the number of threads that are in a process.
View process
1. Top command
Top command to view the system's resource status
Load average indicates how many processes have attempted to monopolize the CPU over a period of time
Zombie Process: Not an exception condition. A process from creation to end in the last period of time is a zombie. The thing that remains in memory waiting for the parent process to take is zombies. Any program has a zombie state, which occupies a bit of memory resources, just the appearance of not fear. If the program has a problem with the opportunity to meet, solving a large number of zombies simple and effective way is to restart. Kill is a stop mode without any effect: unlike the sleep process, sleep will actively abandon the CPU, while stop is a passive abort of the CPU, as a case of single-step tracking, the Stop (pause) process is unable to return to its own running state.
CPU states:
Nice: Yield percent IRQ: interrupt processing occupation
Idle: Percentage of space occupied iowait: input/Output Wait (if it is large indicating that there is a bottleneck outside, you need to upgrade the hard disk (SCSI))
Mem: Memory condition
Design idea: Saving resources is not a waste, such as adding memory after the free value will not change, the buff value will increase. Determine if physical memory is sufficient to see the usage status of the swap partition.
Interactive commands:
[Space] immediately refresh the display
[h] Display help screen
[K] kills a process. You will be prompted to enter the process ID and the signal to be sent to it. The normal termination process can use a 15 signal, and if not, use signal 9 to force end the process. The default value is signal 15. This command is masked in safe mode.
[n] Changes the number of processes displayed. You will be prompted to enter a quantity.
[u] Sorts by user.
[M] sorted by memory usage.
[O] [O] Change the order in which items are displayed.
[P] Sorts according to the percentage size of CPU usage.
[T] is sorted by time/accumulated time.
[Ctrl+l] Erase and rewrite the screen.
[Q] Exit the program.
[R] Reschedule the priority level of a process. The user is prompted to enter the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value lowers the priority and, conversely, it gives the process a higher priority. The default value is 10.
[S] Switches to cumulative mode.
[s] changes the delay time between two refreshes. The user will be prompted to enter a new time in S. If there are decimals, it is converted into M S. Enter a value of 0 and the system will refresh continuously, the default value is 5 S. It is important to note that if you set too small a time, it is likely to cause a constant refresh, so it is too late to see the display, and the system load will be greatly increased.
Abbreviation meaning:
PID ID for each process
Username of user Process Owner
PRI Priority level per process
NI value for each priority
The code size of the size process plus the total number of data size plus the amount of stack space, in kilobytes of the total physical memory occupied by the KB RSS process
The number of shared memory that the share process uses
The status of the STAT process. Where S is the dormant state; D represents an interruptible sleep state; R represents the running state; Z stands for zombie State; T stands for stopping or tracking status
The percentage of CPU time and total time that the%CPU process has occupied since the most recent refresh
The percentage of physical memory that the%MEM process occupies in total memory
The total CPU time that was consumed by the timing process since it was started
CPU CPU ID
command name of the commands process
2. PS command
PS View active process of current user, if add parameter can display more information, such as-A, show all user's process
PS Ax:tty value is "?" Is the daemon, called Deamon No terminal, most of the system service is this process, the kernel state process is not visible
PS AXF: Look at the process tree, in a tree-shaped reality process list knock, Init is the 1th process, the system all processes are derived from it, can not kill
PS AXM: The thread will be listed. Under Linux, processes and threads are unified and are two ways of lightweight processes.
PS Axu: Displays the detailed status of the process.
Vsz: Says how much physical memory this process takes up altogether.
RSS: How much resident memory is requested
========================================================================================
View Threads
In fact, Linux is not a thread, it is the process of imitation
1. Ps-ef F
Show processes and threads in a tree, for example, I want to find out how many processes/threads proftp now have, which can be used
$ 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
This way you can see that the PROFTPD process has two threads hanging under it.
Under Linux it seems that because there is no real thread, it is simulated with a process, one is a worker thread, so the real program thread should only have one.
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 stuff to see the stacks of all threads
How can I see the memory consumption of threads in a process?
With PS aux can only see the process, if the process is using pthread programming, with what command to query the process of thread resource consumption?
PS aux | grep, No.
View processes and threads under Linux