Methods of payment Abuse

See process threads in Linux

06.03.2021, 20:53

Threading is a program abstraction for parallel execution in modern OS. The following happens with multithreaded program execution: RAM address space and open files are shared between threads in order to minimize overhead and use CPU time more efficiently. All this makes multithreaded execution an efficient and useful mechanism. You can view threads using the ps and top command line tools. Next, let's see how to do this in the Linux operating system.

Linux process threads

Linux provides two ways to debug multithreaded processes to perform a particular action. One is when a process creates its own copies using the fork mechanism and then these processes communicate via sockets or IPC. Т. The user gets processes that occupy resources and a certain amount of memory. The next way is to allocate threads within a single process. This way all the threads of a single process will have one thread group identifier as well as a unique identifier. That is, they will have access to all the resources of the parent process and will occupy less memory.

PS utility

In this program, process threads are activated by one command - T. In the following way you can see all process threads with PID for Chromium:

$ ps -T -p

УТИЛИТА PS

The SPID column shows the thread ID and the CMD shows the thread name.

TOP utility

With the help of top utility it is easy to view threads in real time. To do this, you should run top with the -H option. It is possible to enable or disable threads display at runtime using the H key:

$ top -H

If you need to view only the threads of the desired process use:

$ top -H -p pid

УТИЛИТА TOP

As you can see, using top is quite simple.

HTOP utility

However, the most convenient utility for viewing threads is HTOP. It is the main interactive process viewer on ncurces. With its help you can watch threads in real time in the form of a tree.

To do this, you need to enable threads view in htop: first of all, open the program, enter the menu by pressing F2, then select Display Options, under Setup. Now check Three view and Show custom thread names. That's it, you can press F10 to save the settings:

УТИЛИТА HTOP

That's it. This way you can view the threads in a tree view separately for each process. Here again you can see the threads for the Chromium browser:

потоки для браузера Chromium