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 would like to find out which of my ~50 gnu screen windows has a process running with a specific variable defined in it. For example, about a week ago, I did this:

id=ABC123456; ~/run_long_process $id

This is running in one of my ~50 gnu screen windows and it's producing a lot of STDOUT/STDERR but, other than scrolling back each of the windows or Ctrl+Z and resuming each of the windows, is there a way of finding out which one it is? Any suggestions?

share|improve this question
up vote 6 down vote accepted

If this is Linux, you could follow a process something like this. As an example of a "long running process" I'm going to use "perl -e sleep" which just sleeps forever:

$ id=ABC123456; perl -e sleep $id

Now, we need to find the running process:

$ ps -Af | grep [A]BC123456
user  30579 22013  0 09:32 pts/10   00:00:00 perl -e sleep ABC123456
#           ^^^^^ parent PID

Now that we have the parent's PID, we can snoop in its environment, in which screen sets a WINDOW variable:

$ tr '\0' '\n' < /proc/22013/environ | grep WINDOW

Which is correct. I ran it in screen Window 3. Since this is an environment variable, there's a good chance that your task will also inherit it (depending on which flavor of exec() calls are used), so you can probably snoop the environment of your task as well, and find the same result.

share|improve this answer

You must log in to answer this question.

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