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; };

In reply to question on exitcode provided by status() method of Win32::Job by stevehs17

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.