View processes and threads under Linux

Three Ways to Check Thread Count in Linux

1. The top -H
manual says: -H : Threads toggle
Add this option to start top, and the top line displays a thread. Otherwise, it displays one process per line.
2. The ps xH
manual says: H Show threads as if they were processes
so that you can view all existing threads.
3. The ps -mp <PID>
manual says: m Show threads after processes
This allows you to view the number of threads from a process.

View progress

1. top command

The top command to view the resource status of the system

  The load average indicates how many processes have attempted to monopolize the CPU over the past period of time

  Zombie process: Not an exception. A process is zombie all the time from creation to termination. Anything left in memory waiting for the parent process to fetch is a zombie. Any program has a zombie state, it takes up a little memory resources, it is only an appearance and there is no need to be afraid. If there is a chance to encounter problems with the program, the simple and effective way to solve a large number of zombies is to restart. kill is a stop mode without any effect: it should be different from the sleep process, sleep will actively give up the cpu, while stop is passively giving up the cpu, such as single-step tracking, the stopped (suspended) process cannot return to the running state by itself.

  cpu states:

  nice: yield percentage irq: interrupt processing occupancy

  idle: percentage of space occupied iowait: input and output waiting (if it is large, it means that there is a bottleneck in the external storage, and the hard disk (SCSI) needs to be upgraded)

  Mem: memory situation

  Design idea: To save resources and not use them is a waste. For example, after adding memory, the free value will remain unchanged, and the buff value will increase. To determine whether the physical memory is enough, look at the usage status of the swap partition.

  Interactive commands:

  [Space] Immediately refresh the display

  [h] Display help screen

  [k] Kill a process. You will be prompted for the process ID and the signal to send to it. The general termination process can use the 15 signal; if it cannot be terminated normally, use the signal 9 to force the termination of the process. 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] Changes the order of displayed items.

  [P] Sort by CPU usage percentage size.

  [T] Sort by time/cumulative time.

  [Ctrl+L] Erase and rewrite the screen.

  [q] Quit the program.

  [r] rearranges the priority level of a process. The system prompts the user to input the process PID that needs to be changed and the process priority value that needs to be set. Entering a positive value will make the priority lower, otherwise it will make the process have a higher priority. The default value is 10.

  [S] Switch to accumulation mode.

  [s] Change the delay time between refreshes. The system will prompt the user to enter a new time in seconds. If there is a decimal, it is converted to ms. If you enter a value of 0, the system will refresh continuously. The default value is 5 s. It should be noted that if the time is set too small, it is likely to cause continuous refresh, so that it is too late to see the display clearly, and the system load will be greatly increased.

  Abbreviation meaning:

  PID ID of each process

  USER username of the process owner

  PRI priority level of each process

  NI values ​​for each priority

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

  SHARE the amount of shared memory used by the process

  STAT The status of the process. Where S stands for sleep state; D stands for uninterruptible sleep state; R stands for running state; Z stands for dead state; T stands for stop or track state

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

  The percentage of physical memory occupied by the %MEM process to the total memory

  The total CPU time occupied by the TIME process since it was started

  CPU CPU sign

  The command name of the COMMAND process

2. ps command

ps View the active processes of the current user, if you add parameters, you can display more information, such as -a, display the processes of all users


  ps ax: The tty value of "?" is a daemon process called deamon without a terminal. Most system services are this process, and the kernel mode process cannot be seen.

      ps axf : Look at the process tree, and tap the process list in a tree-like manner. Init is the No. 1 process. All processes in the system are derived from it and cannot be killed.

      ps axm : will list the threads. 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: Say how much physical memory this process occupies in total.

  rss: how much resident memory is requested

View thread

In fact, linux does not have threads, it is simulated by processes

1. ps -ef f
displays processes and threads in tree form. For example, if I want to find out how many processes/threads proftp has now, I 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
This way you can see the proftpd process Two threads hang below.
Under Linux, it seems that because there is no real thread, it is simulated by a process, and one is an auxiliary thread, so there should be only one thread opened 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 
can view the general situation

4.  pstack

Some systems can use this stuff, you can view the stack of all threads

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

You can only view the process with ps aux. If pthread programming is used in the process, what command can you use to check the thread resource usage in the process?
ps aux | grep is not enough

 

Original address: http://www.linuxidc.com/Linux/2015-01/111462.htm

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324982464&siteId=291194637