[英]How to get number of threads which was created in “black box” on linux?
让我用代码阐明我的问题:
int main()
{
// call for some function which creates threads
i_create_some_threads();
// I can get PID
pid_t pid = getpid();
// need to get all threads here
// ???
}
我了解解析/proc/PID/tasks/
但是正在寻找一种在我的程序中执行而不解析目录/文件的方式。
有什么办法吗?
涉及的东西
ps -o nlwp <pid>
可能就是您想要的。 -o表示用户定义的输出格式,nlwp是线程数。 这将为您提供如下输出:
NLWP
6
只需尝试执行该命令并在代码中操纵其输出即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.