in reply to Re: Attempt to free unreferenced scalar...
in thread Attempt to free unreferenced scalar...

I commented $SIG{CHLD} and the problem really went away!!!

I would really appreciate if help me to walk around this...

One thing is really important for me, it has to be still multithreaded.
Is this possible with waitpid? I read perldoc -f waitpid and there is some example how to use it "non-blocking" way, but i'm not convinced...

Waiting for Your reply...

PS. I'm the person to thank You all for guiding me how to find the real problem :)

-- Daniellek

Replies are listed 'Best First'.
Re: Re: Attempt to free unreferenced scalar...
by Dominus (Parson) on Dec 01, 2000 at 18:40 UTC
    > 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.

      OK, I did it as you said and... it works!
      No more errors, no more unhappy people ;)

      Thanks! If you ever be in Krakow (Poland), I'll buy you a beer :)

      -- Daniellek
        I'm glad I could be helpful! If I'm ever in Krakow, I'll let you buy me a beer.