Identify in which screen instance a process is running

gnu-screenprocess

A process listening on port 8113 (Solr) is not responding. I've found its PID via netstat but the server has about two dozen Solr process running in various screen sessions.

3607.foobar-client2  (12/27/14 20:54:02)     (Detached)
3797.solr.bo.app    (12/25/14 11:51:30)     (Detached)
2962.solr       (12/25/14 11:47:23)     (Detached)
1410.solrTester         (12/25/14 11:39:41)     (Detached)
1348.solrReports (12/25/14 11:38:41)     (Detached)
....

The only way that I've found to identify them involves stopping the processes. I tried identifying them by which files are open by lsof but that was not helpful at all in this circumstance. Is there any way to determine, based on PID, in which screen session a process is running?

Best Answer

Found it!

To find the screen instance in which PID 351 is running, search the PID 351 environment for the string "STY=":

$ grep -z '^STY=' /proc/351/environ
STY=1410.neverFindMe

Or using ps (if screen session names don't contain space characters):

$ ps wwep 351 | grep -o 'STY=\S*'
STY=1410.neverFindMe
Related Question