Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I frequently VNC into a server where we run many concurrent computationally intensive matlab processes. Sometimes, one of my processes misbehave, which I can see from top, but I have a hard time figuring out which VNC session it's running on, or more specifically, which display it's running on.

Suppose I see that PID 8536 looks like a resource hog, and I want to investigate. Because it's a matlab session, I know there is likely an IDE open somewhere, and I want to check to see if anything important is happening before I kill it.

We've solved this somewhat awkwardly in the past by identifying which PTY 8536 was launched from, then looking at a process tree to figure out things launched in that context, scrolling up, and seeing the VNC initialization.

Seems like there must be a better way to go PID -> X Display (or VNC Session).

share|improve this question
up vote 2 down vote accepted

In the process filesystem there is a file called environ that should contain the environment variables that are set for any given PID, including the variable VNCDESKTOP which should include the screen number of that processes parent VNC session.

This should display the information:

awk -v 'RS=\0' -F = '$1=="VNCDESKTOP" {print $2}' /proc/$PID/environ
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .