This question already has an answer here:
这个问题在这里已有答案:
- POSIX API call to list all the pthreads running in a process 3 answers
- POSIX API调用列出在进程3答案中运行的所有pthread
I want to write a c function , which when called by the process returns number of threads created by that process. I want to get the value not by counting but from the kernel structure ? Which structure has this information ?
我想写一个c函数,当进程调用时返回该进程创建的线程数。我想得到的值不是通过计算而是来自内核结构?哪种结构有此信息?
1 个解决方案
#1
1
You can get a lot of information about your process by looking in /proc/$$
where $$
is your process ID.The number of threads is available atomically through /proc/$$/status
.
您可以通过查看/ proc / $$来获取有关您的进程的大量信息,其中$$是您的进程ID。线程数可通过/ proc / $$ / status以原子方式获得。
My solution: You need write a function to analyse the file /proc/$$/status to get the number of threads.
我的解决方案:您需要编写一个函数来分析文件/ proc / $$ / status以获取线程数。
#1
1
You can get a lot of information about your process by looking in /proc/$$
where $$
is your process ID.The number of threads is available atomically through /proc/$$/status
.
您可以通过查看/ proc / $$来获取有关您的进程的大量信息,其中$$是您的进程ID。线程数可通过/ proc / $$ / status以原子方式获得。
My solution: You need write a function to analyse the file /proc/$$/status to get the number of threads.
我的解决方案:您需要编写一个函数来分析文件/ proc / $$ / status以获取线程数。