0

I have a source code that is using some threads.

I want to see how many percent cpu and percent memory are used each threads.

So I used "htop" command. (I am using ubuntu.)

There are "PID" columns which is Process/thread ID.

I googled how to get thread id.

  1. https://en.cppreference.com/w/cpp/thread/thread/id/hash
  2. How to convert std::thread::id to string in c++?

But, somehow the thread ids I got from source code are not matched with PID values, one of htop command's output.

Any better idea or help would be great, thank you.

drescherjm
  • 10,365
  • 5
  • 44
  • 64

1 Answers1

0

PID is Process ID. Run top -H

man 1 top

-H  :Threads-mode operation
     Instructs top to display individual threads.  Without this
     command-line option a summation of all threads in each
     process is shown.  Later this can be changed with the `H'
     interactive command
273K
  • 29,503
  • 10
  • 41
  • 64
  • I used it. but seems no different. – sisao sin Sep 21 '22 at 05:37
  • What does "no difference" mean? `top -H` must show completely different data. – 273K Sep 21 '22 at 05:38
  • "no difference" means still no match PID with source code output. Thread-mode seems expand and collapse toggle key, process id only or process id with that's thread ids but, any PID no match with source code output that I got from upper links 1, 2. – sisao sin Sep 21 '22 at 06:00
  • I doubt that is data displaying format problem? – sisao sin Sep 21 '22 at 06:01
  • `std::thread::id` is not a real thread id. *This class is designed for use as key in associative containers, both ordered and unordered.* This can be a hash of a real thread id. – 273K Sep 21 '22 at 06:05
  • How can I get a real thread id from the class std::thread::id ?? – sisao sin Sep 21 '22 at 06:08
  • You can do it only in a thread function. – 273K Sep 21 '22 at 06:16
  • 1
    You can look at all threads with `top -H -pPID` with PID of your program. – 273K Sep 21 '22 at 06:22