如何查看已打开套接字连接的进程的线程ID? [英] How to view thread id of a process which has opened a socket connection?

查看:586
本文介绍了如何查看已打开套接字连接的进程的线程ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进程,其中多个线程打开多个套接字连接.我想查看此信息并映射哪个线程打开了哪个套接字端口. lsof -inetstat命令提供了进程ID,但无法显示线程ID.有没有打印此信息的命令?

I have a process where multiple threads open multiple socket connection. I want to view this information and map what thread has opened which socket port. lsof -i and netstat command gives the process ID, but couldn't display thread id. Is there any command which prints this information?

推荐答案

如MarkR所建议的,您需要在启动时使用 strace :

As MarkR suggested, you need to use strace from startup:

strace -fp <pid>

上面的命令将向您显示每个线程的系统调用,例如open(),read(),recv()等,以及所使用的描述符:

The above command will show you per thread system calls like open(), read(), recv() etc, along with the descriptors used:

[pid 428] close(36) 

一旦隔离了线程,就可以附加到进程并使用

Once you isolated the thread, you may attach to the process and find out the exact thread with

gdb attach <pid>

或者,如果您在进程中设置了线程名称,请使用

Or, if you have thread names set in your process, use

ps -eL

找出线程的友好名称.

这篇关于如何查看已打开套接字连接的进程的线程ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆