3 package PerlACE
::Process
;
6 use POSIX
"sys_wait_h";
12 ###############################################################################
14 ###############################################################################
20 if (defined $Config{sig_name
}) {
22 foreach my $name (split (' ', $Config{sig_name
})) {
29 for ($i = 0; $i < 255; ++$i) {
34 ###############################################################################
36 ### Constructor and Destructor
41 my $class = ref ($proto) || $proto;
45 $self->{IGNOREEXESUBDIR
} = 0;
46 $self->{PROCESS
} = undef;
47 $self->{EXECUTABLE
} = shift;
48 $self->{ARGUMENTS
} = shift;
49 $self->{VALGRIND_CMD
} = $ENV{'ACE_RUN_VALGRIND_CMD'};
51 if (!defined $PerlACE::Process
::WAIT_DELAY_FACTOR
) {
52 if (defined $self->{PURIFY_CMD
}) {
53 $PerlACE::Process
::WAIT_DELAY_FACTOR
= 10;
55 elsif (defined $self->{VALGRIND_CMD
}) {
56 $PerlACE::Process
::WAIT_DELAY_FACTOR
= 5;
59 $PerlACE::Process
::WAIT_DELAY_FACTOR
= 1;
63 bless ($self, $class);
71 if ($self->{RUNNING
} == 1) {
72 print STDERR
"ERROR: <", $self->{EXECUTABLE
},
73 "> still running upon object destruction\n";
78 ###############################################################################
87 $self->{EXECUTABLE
} = shift;
90 my $executable = $self->{EXECUTABLE
};
92 if ($self->{IGNOREEXESUBDIR
}) {
96 my $basename = basename
($executable);
97 my $dirname = dirname
($executable). '/';
99 $executable = $dirname.$PerlACE::Process
::ExeSubDir
.$basename;
102 $executable = $dirname.$basename;
105 if ( !-x
$executable ) {
106 if ( -x
$executable.'.exe' ) {
107 $executable = $executable.'.exe';
119 $self->{ARGUMENTS
} = shift;
122 return $self->{ARGUMENTS
};
129 my $commandline = $self->Executable ();
131 if (defined $self->{ARGUMENTS
}) {
132 $commandline .= ' '.$self->{ARGUMENTS
};
143 $self->{IGNOREEXESUBDIR
} = shift;
146 return $self->{IGNOREEXESUBDIR
};
154 $self->{IGNOREHOSTROOT
} = shift;
157 return $self->{IGNOREHOSTROOT
};
160 ###############################################################################
162 # Spawn the process and continue;
168 if ($self->{RUNNING
} == 1) {
169 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
170 "> already running\n";
174 if (!defined $self->{EXECUTABLE
}) {
175 print STDERR
"ERROR: Cannot Spawn: No executable specified\n";
179 if ($self->{IGNOREEXESUBDIR
} == 0) {
180 if (!-f
$self->Executable ()) {
181 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
186 if (!-x
$self->Executable ()) {
187 print STDERR
"ERROR: Cannot Spawn: <", $self->Executable (),
188 "> not executable\n";
193 $self->{PROCESS
} = VmsProcess
::Spawn
$self->{EXECUTABLE
}, $self->{ARGUMENTS
};
194 if ($self->{PROCESS
}) {
200 print STDERR
"ERROR: Can't spawn <" . $self->CommandLine () . ">: $!\n";
202 $self->{RUNNING
} = 1;
210 my $status = $self->TimedWait ($timeout);
213 print STDERR
"ERROR: $self->{EXECUTABLE} timedout\n";
217 $self->{RUNNING
} = 0;
223 # Do a Spawn and immediately WaitKill
225 sub SpawnWaitKill
($)
230 if ($self->Spawn () == -1) {
234 return $self->WaitKill ($timeout);
237 sub TerminateWaitKill
($)
242 if ($self->{RUNNING
}) {
243 print STDERR
"INFO: $self->{EXECUTABLE} being killed.\n";
244 kill ('TERM', $self->{PROCESS
});
247 return $self->WaitKill ($timeout);
250 # really only for internal use
251 sub check_return_value
($)
259 elsif ($rc == 0xff00) {
260 print STDERR
"ERROR: <", $self->{EXECUTABLE
},
264 elsif (($rc & 0xff) == 0) {
276 # check for ABRT, KILL or TERM
277 if ($rc == 6 || $rc == 9 || $rc == 15) {
281 print STDERR
"ERROR: <", $self->{EXECUTABLE
},
284 print STDERR
"coredump from " if ($dump == 1);
286 print STDERR
"signal $rc : ", $signame[$rc], "\n";
295 if ($self->{RUNNING
}) {
296 kill ('KILL', $self->{PROCESS
});
297 waitpid ($self->{PROCESS
}, 0);
298 $self->check_return_value ($?
);
301 $self->{RUNNING
} = 0;
304 # Wait until a process exits.
305 # return -1 if the process is still alive.
310 if (!defined $timeout || $timeout < 0) {
311 waitpid ($self->{PROCESS
}, 0);
313 return TimedWait
($self, $timeout);
323 $timeout *= $PerlACE::Process
::WAIT_DELAY_FACTOR
;
326 my $pid = VmsProcess
::TimedWaitPid
($self->{PROCESS
}, $timeout, $status);
328 return $self->check_return_value ($status);
337 my $procmask = shift;
339 ## NOT IMPLEMENTED YET