> I commented $SIG{CHLD} and the problem really went away!!!Good, that's what I thought it was all along.
>it has to be still multithreaded. Is this possible with waitpid?
Oh, yes, that's why I suggested it. The key to the multithreadedness of your program is the spawn function. You aren't even going to touch the spawn function.
The example of what you need to do is in the manual. If you do waitpid(-1, &WNOHANG), then it checks to see if there is a zombie, and if there is one, it cleans it up. Unlike wait, it returns immediately whether there is a zombie or not. If you use:
do { $kid = waitpid(-1,&WNOHANG); } until $kid == -1;
then your program will clean up all the outstanding zombies. If there are no zombies, waitpid will return -1 immediately and the loop will execute only once.
You can stick this code into your program at the top of the main loop, and every time your server accepts a new client, it will try to clean up any outstanding zombies. Get rid of $waitedpid and the signal handler. Leave spawn the way it is. Put the waitpid loop in just before the call to spawn. Don't forget to use POSIX ":sys_wait_h" like it says in perlfunc.
Hope this helps. Send me email if you can't get it working.
In reply to Re: Re: Attempt to free unreferenced scalar...
by Dominus
in thread Attempt to free unreferenced scalar...
by Daniellek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |