我执行以下 strace 命令,目的是获取有关 PID 13221 的数据
strace -fF -tT -all -o abc.txt -p 13221
然而,当命令执行并完成时,我得到如下输出:
Process 13221 attached with 12 threads - interrupt to quit
Process 13252 attached
Process 13253 attached (waiting for parent)
Process 13253 resumed (parent 13252 ready)
Process 13252 suspended
Process 13252 resumed
Process 13253 detached
Process 13252 detached
Process 13232 detached
Process 13228 detached
Process 13225 detached
Process 13222 detached
Process 13221 detached
这些额外的 PID 是什么?这些是 13221 的 child 吗?谁在创造它们?
谢谢。
最佳答案
What are these extra PID's ? Are these the children of 13221 ?
它一定是你程序的线程。您在 strace 中使用了“-f”,这就是线程也被监控的原因。
How to know which of these are threads
如果你运行 ls /proc/<PID>/task
对于您的进程,您将获得进程中所有线程的 PID(包括主线程的 PID)。
与运行pstack
相比,需要获取线程PID时更简单对于相同的过程。 pstack
实际上是一个 gdb
脚本,它在附加时停止进程。所以只运行 ls /proc/<PID>/task
更简单
关于linux - 在 Strace 命令中查询 PID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25937323/