Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list threads opened by every application in Linux?

Tags:

c++

linux

Is there a way to know, at a real time, what threads are opened and what application opened them?

like image 475
Night Walker Avatar asked Jul 20 '10 13:07

Night Walker


People also ask

How can I tell how many threads a program is using?

Through Windows Task Manager: Open Task Manager (press Ctrl+Shift+Esc) Select Performance tab. Look for Cores and Logical Processors (Threads)

How do I find the thread ID of a process in Linux?

Identifying the thread On Unix® and Linux® systems, you can use the top command: $ top -n 1 -H -p [pid]replacing [pid] with the process ID of the affected process. On Solaris®, you can use the prstat command: $ prstat -L -p [pid]replacing [pid] with the process ID of the affected process.

Does htop show threads?

htop was designed to provide as much information as possible about what's going on in the system. As a result, it displays the user threads instead of hiding them. For example, system administrators can spot a problem in a multithreaded application while monitoring the CPU usage of its related threads.


1 Answers

You can look in /proc/<PID>/task/ (where <PID> is a process-ID) which will have a number of subdirectories, each with the name equal to the thread-ID of one of the threads in that task.

Note that this is only sort-of real-time though -- unless you were to "freeze" the entire system for the duration, the information you get can always be stale, because a process may create or destroy threads even as you're looking at the data.

like image 141
Jerry Coffin Avatar answered Sep 28 '22 03:09

Jerry Coffin