Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

walkingthecow's scratchpad

by walkingthecow (Friar)
on Apr 08, 2010 at 21:55 UTC ( [id://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
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found