[vhffs-dev] [1550] Scheduler doesn't wait for zombie when the pipe is closed |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 1550
Author: guillaumito
Date: 2010-03-06 00:53:31 +0100 (Sat, 06 Mar 2010)
Log Message:
-----------
Scheduler doesn't wait for zombie when the pipe is closed
anymore. Instead it only removes the file from the set
of read files. Zombie are waited for in the "job" loop.
Please review, test and report problems :)
Modified Paths:
--------------
trunk/vhffs-robots/src/cron_scheduler.pl
Modified: trunk/vhffs-robots/src/cron_scheduler.pl
===================================================================
--- trunk/vhffs-robots/src/cron_scheduler.pl 2010-03-05 21:45:13 UTC (rev 1549)
+++ trunk/vhffs-robots/src/cron_scheduler.pl 2010-03-05 23:53:31 UTC (rev 1550)
@@ -100,15 +100,38 @@
if( $job->{'status'} == STATUS_CREATED ) {
run_job( $job ) if( time() > $job->{'runat'} );
}
- elsif ( $job->{'status'} == STATUS_RUNNING ) {
- if( defined $maxexectime && $maxexectime > 0 && time() - $job->{'startedat'} > $maxexectime ) {
- kill 9, $job->{'pid'};
- $job->{'status'} = STATUS_KILLED;
+ else {
+ if ( $job->{'status'} == STATUS_RUNNING ) {
+ if( defined $maxexectime && $maxexectime > 0 && time() - $job->{'startedat'} > $maxexectime ) {
+ kill 9, $job->{'pid'};
+ $job->{'status'} = STATUS_KILLED;
+ }
}
+
+ my $pid = waitpid( $job->{'pid'}, POSIX::WNOHANG );
+ my $returnvalue = $? >> 8;
+ if ( $pid == $job->{'pid'} ) {
+ my $cron = $job->{'cron'};
+
+ $job->{'output'} .= "\n------KILLED------\n" if( $job->{'status'} == STATUS_KILLED );
+
+ if( defined $job->{'output'} && $job->{'output'} ne '' ) {
+
+ my $body = 'Exit value: '. $returnvalue."\n\n";
+ $body .= 'WARNING: This process was killed because it were still running after more than '.$maxexectime.' seconds'."\n\n" if( $job->{'status'} == STATUS_KILLED );
+ $body .= "\n--- Environment ---\n\n".$job->{'env'}."\n\n--- Stdout and stderr output ---\n\n".$job->{'output'}."\n";
+ sendmail_cron( $cron , $body );
+ }
+
+ $cron->quick_set_nextrundate( time() + $cron->get_interval );
+ $cron->quick_set_lastrun( $job->{'createdat'} , $returnvalue );
+ $cron->quick_dec_running();
+ destroy_job( $job );
+ }
}
}
- my ($rh_set) = IO::Select->select($read_set, undef, undef, 1);
+ my ($rh_set, undef, $eh_set) = IO::Select->select($read_set, undef, $read_set, 1);
foreach my $rh (@$rh_set) {
my $job = $fd2jobs{$rh->fileno};
my $cron = $job->{'cron'};
@@ -127,24 +150,7 @@
}
}
else {
- # End of this job
- waitpid( $job->{'pid'} , 0 );
- my $returnvalue = $? >> 8;
-
- $job->{'output'} .= "\n------KILLED------\n" if( $job->{'status'} == STATUS_KILLED );
-
- if( defined $job->{'output'} && $job->{'output'} ne '' ) {
-
- my $body = 'Exit value: '. $returnvalue."\n\n";
- $body .= 'WARNING: This process was killed because it were still running after more than '.$maxexectime.' seconds'."\n\n" if( $job->{'status'} == STATUS_KILLED );
- $body .= "\n--- Environment ---\n\n".$job->{'env'}."\n\n--- Stdout and stderr output ---\n\n".$job->{'output'}."\n";
- sendmail_cron( $cron , $body );
- }
-
- $cron->quick_set_nextrundate( time() + $cron->get_interval );
- $cron->quick_set_lastrun( $job->{'createdat'} , $returnvalue );
- $cron->quick_dec_running();
- destroy_job( $job );
+ $read_set->remove( $rh );
}
}
@@ -317,7 +323,9 @@
my $pipe = $job->{'pipe'};
if( defined $pipe ) {
delete $fd2jobs{ $pipe->fileno };
- $read_set->remove($pipe);
+ if ( $read_set->exists($pipe) ) {
+ $read_set->remove($pipe);
+ }
close($pipe);
}
}