find out the number of threads created by a short running program
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.
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.
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?
精彩评论