Gossamer Forum
Home : General : Perl Programming :

Re: [Alex] Waitpid Spawn error in Perl

Quote Reply
Re: [Alex] Waitpid Spawn error in Perl In reply to
Ok here is what i have
:
the error msg is on the msg above...
the part of the code is this
}

close TEMPFILE;

} elsif ($Param[1] eq '2wayproc') {

$ExtPid = open2(*ExtReader, *ExtWriter, $TempValue );

shout ('debug',"OPEN2: Two-way process with PID $pid spawned.");

select(ExtWriter); $| = 1; select(STDOUT);

}

return;

A friend of mine told me that he did this to his code..

Suppose you run the child process in a loop like I did :

LOOP: while (condition) {

eval { $pid = open2($FHFROM,$FHTO,$Exe,@Params); };
if ($@) {
# then there is an open2() error and error code/message is in $@
}

unless (defined $pid) {
# then the child could not be started for some reason
}


# Now we talk to the child, the child does whatever it has to do and stops

# When we're done ..
# Close up our pipes, collecting status on the way
# By the way, I don't know on which close() we collect the status,
documentation doesn't say
unless (close $FHTO) {
$status = $? >> 8; # get program exit code ?
# etc...
}
unless (close $FHFROM) {
$status = $? >> 8; # get program exit code ?
# etc...
}

sleep 1; # give it time to exit (maybe)

# And here is the essential part to avoid the "Resource not available.." error
:
# waitpid() cleans that child process's remainders out of the process table,
# which otherwise fills up and eventually leads to the "resource not available"
error

$status = waitpid($pid,0);
# I suppose should also get the child exit code in $status


} # end while LOOP


BUT i changed some thngs to use in my prog but it did not work...

Please can someone help me
Thnaks
Subject Author Views Date
Thread Waitpid Spawn error in Perl nacodc 7293 Jan 3, 2003, 10:58 AM
Thread Re: [nacodc] Waitpid Spawn error in Perl
Alex 7171 Jan 6, 2003, 11:35 AM
Thread Re: [Alex] Waitpid Spawn error in Perl
nacodc 7144 Jan 7, 2003, 4:39 PM
Post Re: [nacodc] Waitpid Spawn error in Perl
nacodc 7134 Jan 7, 2003, 4:42 PM