1

I have program that runs fast enough. I want to see the number of threads created by the program.

ldd test 

shows use of library pthread. but how to find out number of threads created by the program. I only have command line access to the PC on which the program is run. The platform is linux.

2 Answers 2

3

Perhaps using strace and catch the calls to clone?

# strace -f -e trace=clone test

It should give an indication of the processes created by test.

Sign up to request clarification or add additional context in comments.

3 Comments

strace not present on the system. may be i can copy a 64-bit version of strace along with the required shared libraries to try this
strace is an extremely useful utility that traces the system calls made by an application. should be easy to install. I edited the answer to reflect a more specific way to catch calls to clone()
This is the best solution. As this is a non-production machine, you can install strace. Strace is shipped with your distribution.
1

Using LD_PRELOAD, you should be able to wrap pthread_create sufficiently enough to log somewhere each time it is entered. That method is flawed, however, because it could introduce (or expose) races in your program that would not otherwise occur, possibly resulting in more or fewer threads being created.

Is just keeping track of this within the program (i.e. if a debug build) not an option?

2 Comments

what if the executable is closed source?
or a library like mpi is creating threads for its implementation, which is what i am trying to use. of course, mpi source code can be studied but i wanted to know for the general case.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.