How to view thread id of a process which has opened a socket connection?

后端 未结 2 1678
野趣味
野趣味 2021-01-17 19:17

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

相关标签:
2条回答
  • 2021-01-17 19:31

    Unless you strace()'d the process, no.

    Once the file descriptor is open, it "belongs" equally to all the threads in the process (as far as the kernel is concerned), you can't see which thread opened it.

    0 讨论(0)
  • 2021-01-17 19:56

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

    strace -fp <pid>
    

    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
    

    to find out the thread's friendly name.

    0 讨论(0)
提交回复
热议问题