如何计算正在运行的线程(pthreads)的数量? [英] How do I count the number of running threads (pthreads)?
问题描述
如果我要计算应用程序具有的线程数,则所有答案都涉及诸如top
之类的外部程序.我想计算应用程序本身中的线程.
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 application itself.
我无法在线程创建时添加代码,因为它发生在不可变的库中.
I can't add code at the point of thread creation because it happens inside an immutable library.
我看不懂/proc
.
这是在几个不同的Unices上运行的C/pthreads程序.
It's a C/pthreads program running on a few different Unices.
推荐答案
如果您无法阅读/proc
,则可能会遇到麻烦,除非您的程序与另一个读取/proc
If you can't read /proc
you are a bit in trouble, unless your program communicate with another program which reads /proc
如果由于可移植性问题而不想读取/proc,则可以使用像libproc
这样抽象的库
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
这篇关于如何计算正在运行的线程(pthreads)的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!