top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to check number of running threads in a multi threaded program and machine also has multiple cores ?

0 votes
575 views
How to check number of running threads in a multi threaded program and machine also has multiple cores ?
posted May 24, 2014 by Ganesh Kumar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

The way I find the number of threads while debugging the my code using gdb is using the command info threads.

  1. Start your program with gdb (For ex: gdb a.out),
  2. Put a break point some where in the code (Make sure that break point is applied only after creating all threads in the system).
  3. run the command info threads, this will list the number of threads created adn presently running in the context of your program.
answer May 26, 2014 by Nagaraja Sadar
0 votes

With the help ot top command also you can see,
for ex:
top -H -p procees-id
it will display following information of all threads present in that process.
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

answer Dec 2, 2014 by Bheemappa G
Similar Questions
+2 votes

write functions to read and write in a hash table in a multi threaded environment. Approach should give decent optimization in terms of time complexity.

0 votes

I have a pool of worker threads, created like this:

threads = [MyThread(*args) for i in range(numthreads)]
for t in threads:
 t.start()

I then block until the threads are all done:

while any(t.isAlive() for t in threads):
 pass

Is that the right way to wait for the threads to be done? Should I stick a call to time.sleep() inside the while loop? If so, how long should I sleep? That's probably an unanswerable question, but some guidelines on
choosing the sleep time will be appreciated.

...