#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    19
    Rep Power
    0

    Monitor multiple programs and do something when they close


    Hi there,

    My Perl's rather rusty and I've been struggling with this task for most of the day - I suspect I just lack the knowledge of more advanced flow control.

    So my problem is that I need to monitor several programs running and when each finishes I need to report it.

    I have an array that contains identifiers for the programs - the @samples array contains simple refs which are grepped out of the squeue output (slurm reporting function, kinda like doing ps).

    Code:
    foreach my $sample (@samples){
    my $running=`squeue | grep b2fq$sample`;
    if(!$running){
    print "Sample $sample seems to have finished\n";
    }
    }
    The code above as it stands will of course execute straight through unless any of the programs have stopped. I've tried using various do...while commands to keep it going but I keep managing to mess it up!

    I need the code to keep executing until ALL the programs listed in @samples have finished.

    Can anyone help? Thanks in advance.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    843
    Rep Power
    496
    Put the whole code into a infinite loop together with a sleep for a few second each time. Your programm will then poll for processes every 5 or 10 (or whatever) seconds. Exit the loop when you are done.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    19
    Rep Power
    0
    Yeah I tried that but my trouble was the break point. If I stick a counter in the is not running part then it ends up incrementing to much. If I use splice to reduce the samples array each time a program stops then it messes up when there is only one program running...

IMN logo majestic logo threadwatch logo seochat tools logo