LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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, 03:52 PM   #1
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,441

Rep: Reputation: 81
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 03:53 PM.
 
Old 11-19-2012, 04:47 PM   #2
toiletresin
LQ Newbie
 
Registered: Jan 2010
Posts: 9

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

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
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, 06:32 AM   #4
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: san antonio, texas
Distribution: Fedora 64 bit RAID0 + LUKS, CentOS (server), Backtrack, Gentoo Hardened
Posts: 1,441

Original Poster
Rep: Reputation: 81
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 06:15 PM
Running server in shared screen session deus1 Linux - Server 1 04-04-2008 01:28 PM
Starting a command in an already-running screen session Wynd Linux - General 1 10-24-2007 04:10 PM
running X in a screen session jumanji Linux - General 2 04-22-2004 02:57 PM
Running a command in a screen session ifan Linux - Newbie 0 07-16-2003 08:12 AM


All times are GMT -5. The time now is 04:00 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration