ubuntu 16.04

I have 2 node applications, app-1 and app-2, with usernames matching their application names, listening locally (on ports 8001 and 8002, respectively) on the same instance. When app-1 makes a request to app-2 I can find the remoteHost of the socket handling the request from app-2. Then when I try to look up this remoteHost via netstat and retrieve some user/process information, I find that the user associated with the socket is uid: 0 or root. My expectation is that the user associated with this connection would be app-1, since that is the application where the request is being generated. So part 1 of my question is: why is the user root and not app-1?

Part 2: My goal is to get the user id of the remote process based solely on the information in remoteHost (e.g. Seems to me like the operating system should know exactly what process/user-id is using that host/port combination. So, assuming netstat will not work, for the reasons mentioned in the previous paragraph, what other system calls or utilities could I look at to get this information?


Embarrassingly, I think the problem in part 1 is that I was only examining the connection after it had already been closed on 1 side (the state was time-wait). As a test I changed the connection type to keep-alive and now the user information appears as expected.

The answer for part 2 will then be reading the same files as netstat (/proc/net/*) and searching for the remoteHost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.