找出短时间运行的程序创建的线程数
我的程序运行得足够快。我想查看程序创建的线程数。
ldd test
显示库 pthread 的使用。但如何找出程序创建的线程数。我只能通过命令行访问运行该程序的电脑。 平台是linux。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许使用 strace 并捕获对克隆的调用?
# strace -f -e trace=clone test
它应该指示测试创建的进程。
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.
使用
LD_PRELOAD
,您应该能够足够充分地包装pthread_create
,以便在每次输入时记录到某处。然而,该方法是有缺陷的,因为它可能会在程序中引入(或暴露)本来不会发生的竞争,从而可能导致创建更多或更少的线程。仅仅在程序中跟踪这一点(即如果是调试版本)不是一个选择吗?
Using
LD_PRELOAD
, you should be able to wrappthread_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?