How to get active unix domain sockets for a specific pid if I can’t use lsof command

netstatsocket

If I have no permission to use lsof, how do I get them for a process with pid already known? Thanks

I know netstat -l -p command print out active unix domain sockets, but it seems it's not updating ? after I closed the socket, it still shows up in netstat command result.

Best Answer

On Linux you can look through the /proc filesystem specifically for a given PID under /proc/<pid>/fd. All the file descriptors (fd) are listed there per process.

Example

$ ls -l /proc/27634/fd/
total 0
lrwx------ 1 root root 64 Mar 17 20:09 0 -> /dev/null
lrwx------ 1 root root 64 Mar 17 20:09 1 -> /dev/null
lrwx------ 1 root root 64 Mar 17 20:10 10 -> /dev/ptmx
lrwx------ 1 root root 64 Mar 17 20:10 12 -> /dev/ptmx
lrwx------ 1 root root 64 Mar 17 20:10 13 -> /dev/ptmx
lrwx------ 1 root root 64 Mar 17 20:09 2 -> /dev/null
lr-x------ 1 root root 64 Mar 17 20:09 3 -> socket:[430396]
l-wx------ 1 root root 64 Mar 17 20:09 4 -> socket:[430437]
lrwx------ 1 root root 64 Mar 17 20:09 5 -> pipe:[430440]
l-wx------ 1 root root 64 Mar 17 20:10 6 -> pipe:[430440]
lrwx------ 1 root root 64 Mar 17 20:10 7 -> socket:[430443]
lrwx------ 1 root root 64 Mar 17 20:10 8 -> socket:[430444]
lrwx------ 1 root root 64 Mar 17 20:10 9 -> socket:[430446]

Everything listed there as socket:[....] is a socket.

Related Question