Skip to content

Instantly share code, notes, and snippets.

@jschwinger233
Last active March 26, 2020 18:24
Show Gist options
  • Save jschwinger233/24883ae4e432d6ff3a100bf5534a0dc7 to your computer and use it in GitHub Desktop.
Save jschwinger233/24883ae4e432d6ff3a100bf5534a0dc7 to your computer and use it in GitHub Desktop.

如何查 unix socket 的 peer

比放说我想确认一个进程是否连接了 unix:///var/run/docker.sock, 对于 TCP 来说 lsof -p$PID | grep $PORT 立刻就能查到, 对于 Unix Socket 来说就不行了.

做法应该是这样的:

  1. lsof 找到这个进程所有的 Unix + SOCK_STREAM 的 sockets, 倒数第二列是 Node Number
  2. ss 找到这个 node number 的 peer
  3. 确认 peer 是 docker sock

写成一句话就是:

for no in $(lsof -p36370 | awk '/unix/ && /STREAM/ {print $8}'); do ss -xp | grep $no; done | grep /var/run/docker.sock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment