LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2012, 02:52 PM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Rep: Reputation: 85
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?

Last edited by fakie_flip; 11-19-2012 at 02:53 PM.
 
Old 11-19-2012, 03:47 PM   #2
toiletresin
LQ Newbie
 
Registered: Jan 2010
Posts: 9

Rep: Reputation: 0
ps ax | grep screen
 
Old 11-19-2012, 04:52 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
1 members found this post helpful.
Old 11-21-2012, 05:32 AM   #4
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495

Original Poster
Rep: Reputation: 85
Quote:
Originally Posted by theNbomr View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Input to a screen session from a script running outside Skaperen Linux - Software 0 08-01-2012 05:15 PM
Running server in shared screen session deus1 Linux - Server 1 04-04-2008 12:28 PM
Starting a command in an already-running screen session Wynd Linux - General 1 10-24-2007 03:10 PM
running X in a screen session jumanji Linux - General 2 04-22-2004 01:57 PM
Running a command in a screen session ifan Linux - Newbie 0 07-16-2003 07:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration