Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 5 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
WINDOW=3

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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