2

I have a server application that binds a unix file socket on /var/run/appsocket.

I have multiple clients which connect to this unix file socket, and I want to be able to determine which PID is connected to this unix file socket.

What I've tried:

sudo lsof /var/run/appsocket

Displays the following:

appserver 101 appuser 6u unix 0x5d3497ad372af941 0t0 /var/run/appsocket

appserver 101 appuser 9u unix 0x5d3497ad3aa380a9 0t0 /var/run/appsocket

This displays which process created the unix file socket, but not the one who is using it. If I list open files by my app client, I see that it is using the file handle 0x5d3497ad372af941 (from the list above).

I've tried using several solutions from here, but nothing worked. I'm using lsof 4.89 and -E is not supported for some reason.

How can I make this connection between the file handle and the process which opened it?

EDIT

sudo lsof /var/run/appsocket | awk '{print $6}' | uniq | xargs -I {} sh -c "sudo lsof -U | grep {}" | awk '{print $1}' | uniq

Does the trick, but is not optimal whatsoever...

  • Try netstat, that does socket connections too – John Keates Jan 23 '17 at 12:50

You must log in to answer this question.

Browse other questions tagged .