http://www.perlmonks.org?node_id=871846

stevehs17 has asked for the wisdom of the Perl Monks concerning the following question:

I have a question on the Perl module in CPAN, Win32::Job. I'm using the module to impose a timeout on a script I want to run.

My question is this. In the code in the function below, I check the value of the exitcode returned by the spawned script (see the line " $state = $rs->{$pid}{exitcode};"), which the spawned script explicitly sets (when it can).

However, in come cases, I get 13 as a value for the exitcode returned by the spawned script, which isn't one of the values I return from the spawned script. In those cases, the spawned script seems to have been aborted, though I can't always tell why. (I should mention that I'm using the script for monitoring a complicated system that has a lot going on, so it's not altogether surprising that the spawned script should run into problems from time to time - though I'd like to know what they are.)

I've gone through the documentation for the Win32::Job on CPAN, and I've done some Google searches and searches on this site, and I haven't been able to figure out what a 13 returned as an exitcode means. Can you tell me what it means, or, at least, where I can look to find this out?

Thanks, Steven

use Win32::Job; sub runmons { my ($job, $pid, $ro, $timeout, $rs, $state, $w, $pfx); init(); oprn("Starting script " . basename($0) . '...', c::STARTPFX, $0); $job = Win32::Job->new(); die 'Failed to create Job object' unless ($job); oprn("Spawning process to run $CHILD...", c::NOTEPFX, $0); $pid = $job->spawn(undef, "perl $CHILD $0"); die "Failed to spawn process to execute $CHILD" unless ($pid); $ro = XMLin(c::MONOPTS, ForceArray => 1); $timeout = $ro->{timeoutsecs}[0]; die 'Timeout length not specified in ' . c::MONOPTS unless defined($timeout); oprn("Running $CHILD as PID $pid with a timeout of $timeout second +s...", c::NOTEPFX, $0); $job->run($timeout); $rs = $job->status(); $state = $rs->{$pid}{exitcode}; unless (grep { $state == $_ } @c::KNOWNERRVALS) { oprn("Error: received unknown exit code = $state from $CHILD. +Will convert to exception.", c::ERRPFX, $0); $state = c::EXCEPT; } $state == c::SUCCESS ? ($pfx = c::NOTEPFX) : ($pfx = c::ERRPFX); $w = errword($state, $0); oprn(basename($0) . " received exit code $state from $CHILD ($w)." +, $pfx, $0); return $state; };