Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

walkingthecow's scratchpad

by walkingthecow (Friar)
on Apr 08, 2010 at 21:55 UTC ( #833643=scratchpad: print w/ replies, xml ) Need Help??

#!/usr/bin/perl use strict; use warnings; system("clear"); my ( $who_am_i, $countdown_pid, $checking_pid ); $countdown_pid = fork(); if ( $countdown_pid == 0 ) { $who_am_i = "countdown process"; } elsif ($countdown_pid) { $checking_pid = fork(); if ( $checking_pid == 0 ) { $who_am_i = "checking process"; } elsif ($checking_pid) { $who_am_i = "controlling process"; } else { die "Error forking: $!"; } } else { die "Error forking: $!"; } for ($who_am_i) { if ($who_am_i eq "countdown process") { sleep_count( 3, 'Verifying with Nagios that resin is down: ' ) +; } if ($who_am_i eq "checking process") { my $test_check = `/bin/ps -u dramaya`; my $counter = 0; while ( $test_check =~ /vi/ ) { if ( $counter == 310 ) { die "Could not verify if resin is down\n"; } $test_check = `/bin/ps -u dramaya`; sleep 10; $counter++; } } if ($who_am_i eq "controlling process") { # Wait on the "checking process" to complete. waitpid($checking_pid, 0); # Kill countdown timer kill(9, $countdown_pid); waitpid($countdown_pid, 0); } } print "$countdown_pid $checking_pid\n"; sub sleep_count { my $minutes = shift; my $string = shift; my $countdown = $minutes * 60; # in secs. $| = 1; my $beg_time = time; my $end_time = $beg_time + $countdown; for ( ; ; ) { my $time = time; last if ( $time >= $end_time ); printf( "\r[ %02d:%02d ] $string", ( $end_time - $time ) / (60) % 60, ( $end_time - $time ) % 60, ); sleep(1); } }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-04-18 04:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (461 votes), past polls