How do I count the number of running threads (pthreads)?

后端 未结 3 1047
眼角桃花
眼角桃花 2021-01-19 23:46

If I search for counting the number of threads an application has, all the answers involve external programs like top. I want to count the threads within the ap

相关标签:
3条回答
  • 2021-01-19 23:49

    Use top -H. But chances are, if you can't read proc, top won't work anyway. If thats the case, there is no easy way and it would depend on your specific system.

    0 讨论(0)
  • 2021-01-20 00:01

    You could write a tiny wrapper for pthread_create that counts created threads and link against that wrapper after you linked against the immutable library.

    0 讨论(0)
  • 2021-01-20 00:09

    If you can't read /proc you are a bit in trouble, unless your program communicate with another program which reads /proc

    If you don't want to read /proc because of portability concerns, you might use a library which abstracts that a bit, like libproc does

    0 讨论(0)
提交回复
热议问题