How can I tell which Screen sessions are still running a PHP process from the command line?

I have about 25 Screen sessions running PHP scripts.

How can I tell which ones are still running the PHP process launched from that Screen session, without having to resume each Screen? Can I access this information from the command line with built in functionality of screen or linux, or do I have to write scripts to handle this?

I started my screen sessions from the command line and executed the PHP scripts the same way.

-------------Problems Reply------------

If my memory serves me right, a screen session (if started with a command, I think it is -x) will kill itself (the screen will exit) when the program is finished running, so you could just parse the screen -list and see if the screen (with the session name you assigned it) is still there.

Alternatively (and what I would do) you could add a running row to a table when the script is started in the screen (with information like what it is doing, expected completion time, screen it's running on etc). Then just have the screen delete the row from the database when it completes, and you have a nice view of everything that is going on, and where it's happening.

You could even limit the number of screens, and have an administration program run in the background to assign jobs to screens (checking the database for when a screen is open).

Personally, I'd run a cronjob or script that will ps auxw | grep screen and then loop through each line, using awk and every other nice tool to see what is currently running on that tty and the idle time of that tty ... chances are, if the PHP script has finished running, it will show that there is nothing running on that tty and you can kill that screen or even just the tty ...

Category:php Views:1 Time:2011-07-12

Related post

  • Running shell script in detached screen session. Must kill. How? 2009-07-23

    I am an Ubuntu Linux user. I am running jobs remotely and started a screen session. During this session I sourced a file containing a long list of command lines arguments to be executed. I was forced off of the connection and now the jobs are still r

  • Sending commands to the active program in a screen session? 2010-08-14

    I've got a server running inside a screen session, and I want to send this program a command. I thought screen -X was my answer, but all that gives me access to is screen commands (title, exec, etc). I need to be able to send the command as if I was

  • Automatically (or more easily) reconnect to a screen session after network interruption 2009-01-23

    ADDED: This question is now, I believe, subsumed by this one: See also this related question:

  • Cannot detach screen session 2009-02-10

    I am very new to screen and I have hit C-Something instead of C-a. Now I cannot detach or do any other commands. What can I do to detatch my screen session? --------------Solutions------------- Possibly you got C-s (s for "stop") try C-q to resume...

  • How to list running screen sessions? 2009-02-11

    I have a bunch of servers, on which I run experiments using screen. The procedure is the following : ssh to server XXX launch screen start experiments in a few tabs detach screen disconnect from the server While the experiments are running, I can eas

  • Gnu-Screen: Run script that sends commands to the screen session it is being run in 2009-05-22

    Is it possible to write a script to change the name and turn on monitoring for the current tab assuming that it is being run in screen? Thanks. --------------Solutions------------- I think this works: if [-n "$STY"]; then screen -X title "foo" screen

  • How to start a new process in a new window in an existing GNU screen session, from outside the session 2009-08-06

    I asked a similar question here and got pretty close to what I'm looking for ...but, this doesn't quite get to what I'm after,

  • Writing a script to close screen session 2009-09-01

    I have a bunch of screen sessions running on my machine, but all of them are detached and unneeded. Is there a good way to just close all of them, so I have nothing when I type "screen -ls"? --------------Solutions------------- how about $killall scr

  • Kill detached screen session 2009-10-02

    I learned from somewhere a detached screen can be killed by screen -X -S [session # you want to kill] kill where [session # you want to kill] can be gotten from screen -ls . But this doesn't work. Anything wrong? What's the correct way? -------------

  • how can I make vim send command to gnu screen session 2009-10-03

    I am trying to figure out how to script vim to send a message to a gnu screen "window". i.e. I have a screen session open and in one window I have a vim session and in the other a scheme interpreter. When I save my vim session I would like it to rest

  • convert.php does not run in a screen session 2010-01-24

    I am trying to convert a big forum. At the moment I have to do this via ssh and start convert.php with "php5 -f convert.php -- $OPTIONS". But my internet connection is a bit buggy and so it is often killed. If i start the above working command in a s

  • how do you script gnu screen from within a screen session to open new windows and run commands in them? 2010-01-28

    From within a screen session, I'd like to run a shell script that opens a few new screen windows in the same session and start running some programs in them. I need a script like this: screen -t newWindow [switch to newWindow and execute a command] s

  • Spawn a screen session from launch daemon 2010-02-21

    I've written a launchd .plist which should attach a debugger to the WindowServer when it launches. The main part of the script looks like screen -D -m -S "WindowServer Debugger" \ gdb \ -x $GDBSCRIPT \ /System/Library/Frameworks/ApplicationServices.f

  • How can I list screen sessions by name? 2010-09-09

    With screen, I know I can name & re-attach to sessions by name: screen -S <name> screen -r <name> When I execute screen -ls I get a list sessions, but the name is not displayed. How do I see the names of my running sessions? ---------

  • Detach and reattach a complete Screen session with multiple windows 2010-12-28

    I am writing a client/server-application and when I'm testing the code I want to be able to have both the server and client in a separate terminal (+ vim). For this I thought I could use GNU Screen and divide the terminal in multiple windows (and it

  • Hudson-CI launched screen session terminates when task ends 2011-03-09

    The main problem I'm having is to background a screen session from Hudson-CI. The shell steps are that I need to start a screen session from a script that is launched by another script. Heres' a simple test: #!/bin/bash myscreen.

  • Is it bad to run a long-running process on a server in a Gnu Screen session? 2011-03-18

    I have a long running process that currently logs output to stderr, and I'm just starting it up and leaving it running on the server within a gnu screen session on the server, which I just detach when I logout of the server and reattach after I log i

  • in Screen, how do I send a command to all virtual terminal windows within a single screen session? 2011-06-28

    I know how to create multiple windows within a single screen session, at startup: But once I have them up and running, is there a way I can have my input be sent to all open windows, not just the one currently in focus? --------------Solutions-------

  • Launch multiple scripted screen sessions from another script 2011-07-26

    I've written a script (that doesn't work) that looks something like this: #!/bin/sh screen -dmS "somename" $HOME/ j=13 for i in {0..5}; do screen -dmS "name$i" $HOME/ $i $j j=10 done For some reason, if I copy and paste t

Copyright (C), All Rights Reserved.

processed in 0.194 (s). 11 q(s)