Wednesday, September 4, 2013

finding a screen in which process in running.

If you are working with screen and you have lot of active screens and each one with lot of tabs. If you want to find a screen in which particular process with some pid is running then I could not find any command which does so.  eg:
        What to find screen in which instance of vim is running then there is no inbuilt command to do so.

So Written a small one line complex script for the same.

Just set $CHILD_PID ( or replace the $CHILD_PID) with the pid of process, which is running under screen.

Output will be a line which  shows only  a screen pid (which you could use to log into corrosponding screen)

${ screen -ls | cut -d "." -f  1 | while read PID; do pstree -p $PID | grep "$CHILD_PID" > /dev/null; if [ $? = 0 ]; then echo "$PID" > sam; fi; done } 2>/dev/null; tail sam

After logging into screen you will have to search each and every tab, to find the process.
Process might be running in the backgound so do not forget to do $jobs. 

No comments:

Post a Comment