Linux API to determine sockets owned by a process

后端 未结 7 2110
被撕碎了的回忆
被撕碎了的回忆 2020-12-23 01:50

Is there a Linux library that will enable me to tell what IP sockets are owned by what processes? I guess I\'m looking for the programmatic equivalent of lsof -i

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-23 02:23

    I think you first have to look through the open fds in /proc/*/fd, e.g.

    4 -> socket:[11147]
    

    and then look for the referenced sockets (by the inode) in /proc/net/tcp (or /proc/net/udp), e.g.

    12: B382595D:8B40 D5C43B45:0050 01 00000000:00000000 00:00000000 00000000  1000        0 11065 1 ffff88008bd35480 69 4 12 4 -1
    

提交回复
热议问题