Linux – why do I find (under /proc/pid//fd) sockets with broken symlinks

linuxprocsocket

I don't think they're closed, because I would expect that after a close() the fd would disappear, but I see a bunch of lingering fd -> socket[xxxxx] entries with broken symlinks which don't seem to be going away quickly. What causes this state?

Best Answer

The socket[xxxxx] symlinks are always broken. There isn't a path you can provide to open a socket with a given inode number.

I tried it and it seems you can't open the file /proc/pidX/fd/Y which refers to a socket. However you can if it refers to a real file, even if the file has been deleted. It's not exactly a symlink. It's magic (i.e. a special case).

Related Question