in reply to Win32 script dies under high load

What do you mean by "fails"? Does the script die? Or the tail fails to return? Or the script fails to detect max connections?

If the script is failing to detect the max connections situtation then my first guess would be the logfile you are looking at is being updated much more often than you expect -- i.e. more than 10 lines every couple of seconds. In which case you should look into monitoring the file directly (as mjscott2702's suggests in Re: Win32 script dies under high load) instead of shelling out to run an external command. It's also possible that if another process is hogging the CPU then your "sleep 2" may actually take more than two seconds.

If you are having problems with the tail returning and want to stick with using it then you may want to look into using alarm. Here's some sample code you could adapt to your situation:

sub cmd_wrapper { my( $cmd ) = @_; my( $rc , $out ); eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm 15; $out = (`$cmd`)[0]; # Get first line of output $rc = $?; alarm 0; }; if( $@ ) { die "Eval failed for $cmd but not because of alarm" if $@ ne " +alarm\n"; # Propogate unexpected errors die "Eval failed for $cmd because alarm timed out"; } die "Return code undefined for $cmd" unless defined $rc; return $rc, $out if wantarray; return $rc; }