Let /var/run/mysqld/mysqld.sock/
be an open socket. I can stat
it to get inode of the file (here 1200)
# stat /var/run/mysqld/mysqld.sock
File: /var/run/mysqld/mysqld.sock
Size: 0 Blocks: 0 IO Block: 4096 socket
Device: 17h/23d Inode: 1200 Links: 1
Access: (0777/srwxrwxrwx) Uid: ( 109/ mysql) Gid: ( 121/ mysql)
Access: 2020-08-24 07:06:50.716419994 +0200
Modify: 2020-07-20 14:51:30.892060665 +0200
Change: 2020-07-20 14:51:30.892060665 +0200
However, what I want is not the disk filesystem inode (ext4 or similar), but OS socket inode as reported in /proc/net/unix
(4517115):
# grep mysqld.sock /proc/net/unix
ffff9efa85f1bc00: 00000002 00000000 00010000 0001 01 4517115 /var/run/mysqld/mysqld.sock
The question is, given filesystem socket inode (1200), how can I retrieve OS socket inode (4517115)? Unfortunately, I can rely on neither ss
, lsof
, or even /proc/net/unix
as those sources are unreliable when the socket file has been created (for example) by a container:
- ss, lsof and others often do not list these sockets at all (maybe those tools rely on
/proc/net/unix
?), /proc/[pid]/net/unix
is unreliable as it may be impossible (or at least hard) to match a file mapped from host to a different path in container. Furthermore,/proc/net/unix
itself might not list these sockets.
ss
in the wrong (namespace) environment? – A.B Aug 25 '20 at 13:52/proc/<pid>/fd
(the number fromsocket:[num]
). – pizdelect Aug 25 '20 at 13:54/proc/net
->/proc/self/net
they get their info via unix_diag netlink sockets (a newer interface). Use/proc/pid-from-other-net-namespace/net/unix
or runss
, etc viansenter
if you want to gather info from other containers. – pizdelect Aug 25 '20 at 14:01nsenter
+/proc/self/net/unix
+stat
on the file listed there to do that. It's slow though as I do that for every PID in the host /proc/. – matt Aug 25 '20 at 14:05