LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Determining if a screen session is already running (https://www.linuxquestions.org/questions/programming-9/determining-if-a-screen-session-is-already-running-4175437839/)

fakie_flip 11-19-2012 02:52 PM

Determining if a screen session is already running
 
Code:

[cam0@beastlinux ~]$ screen -ls
There is a screen on:
        26258.pts-6.beastlinux  (Attached)
1 Socket in /var/run/screen/S-cam0.

[cam0@beastlinux ~]$ echo $?
1
[cam0@beastlinux ~]$ screen -ls
No Sockets found in /var/run/screen/S-cam0.

[cam0@beastlinux ~]$ echo $?
1
[cam0@beastlinux ~]$

I've tried getting the return value from screen -ls, but the value seems useless for me. How should I go about this?

toiletresin 11-19-2012 03:47 PM

ps ax | grep screen

theNbomr 11-19-2012 04:52 PM

To some degree, I think it depends whether you need to determine whether screen is running, or whether a specific screen session is running. Clearly your version of screen doesn't provide any help via the return value. Your recourse then is to parse the output of 'screen -ls'. What kind of parsing you do would be reflected in your objectives. A simple version might be:
Code:

screen -ls | grep 'No Sockets'
to see if any sessions exists for your UID. More elaborate schemes can be used to re-attach to a specified screen name.

--- rod.

fakie_flip 11-21-2012 05:32 AM

Quote:

Originally Posted by theNbomr (Post 4832870)
More elaborate schemes can be used to re-attach to a specified screen name.

No, since I always use 1 screen session for my user,

screen -x

or

screen -x user/

works just fine.

Thanks for the tip of checking with grep.


All times are GMT -5. The time now is 12:33 PM.