Gossamer Forum
Home : General : Perl Programming :

Waitpid Spawn error in Perl

Quote Reply
Waitpid Spawn error in Perl
Hello i have a perl program that uses the get and post method.

But afther 64 cicles, it gives me this error msg:

open2: IO::Pipe: Can't spawn-NOWAIT: Resource temporarily unavaliable at horseland_cracker.pl line 443
i think it means that it is not closing or eliminating the zombies(dead threads)...

some people say that i need to put the waitpid, but it stops responding when i use the waitpid ($pid,0);

and when i use the -1 it gives the same error smg afther the 64 cicles....i saw o a site that the waitpid does not work on windows...can anyone help me find a solution, or a way to adept or use the waitpid...

the part of the code is bellow (line443)

}

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;

Quote Reply
Re: [nacodc] Waitpid Spawn error in Perl In reply to
You need to narrow things down and post a small repeatable example of the problem, but it sounds like you are continuously spawning children, and the children never die.

Cheers,

Alex
--
Gossamer Threads Inc.
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
Quote Reply
Re: [nacodc] Waitpid Spawn error in Perl In reply to
He also said this
"The idea is as follows :
- each time you start a child process, it occupies a new position in some
internal process table, which can contain maximum 64 processes under NT
- even if the child process terminates, that position in the internal
process table is still occupied, and the only way to clear it and make it
available
again, is to do a waitpid(), with the process-id of the (now dead) child.
That process-id is what is (originally, right after the call to open2()) in
the $ExtPid variable.

So you must find out, in your program, when the child process has finished
it's work, and then do a waitpid() on it's process-id to clean the table.

If you don't do that, then slowly the table gets full, and when you have 64
"dead" processes in it, you will get this error when you try to start
another one.
"

He could not find another solution or view my codes and addpet it...
I hope someone can help me
Thanks a lot