in reply to Socket question Help!

The problem seems to be in your SIGCHLD handling code. In it you do:
1 until (-1 == waitpid(-1, WNOHANG));
which is never if you already have a child, sending this into an endless loop. If you have client 1, and client 2 exits, the parent goes into this code, but waitpid will not return -1 (as client 1 is still there). This loop will only stop spinning once all clients are dead - which is exactly what you observe.

You should just call waitpid, which will block until the child has delivered its status, but that is no problem as you are in your SIGCHLD handler, so a child has died per definition:

sub reap { waitpid(-1); return $?; }
Judging by your code, you seem to want to avoid the parent blocking in the waitpid call, but as you waitpid() in the dead child signal handler, blocking will not happen. Ironically, by trying to avoid blocking, you send your server in an endless loop, thus blocking it :).

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: Socket question Help!
by drake50 (Pilgrim) on Nov 17, 2002 at 23:16 UTC
    Okay, I changed the code to read like:
    sub REAP {
            print "reaping\n";
            #1 until (-1 == waitpid(-1, WNOHANG));
            #$SIG{CHLD} = \&REAP;
            waitpid(-1);
              return $?;
    }
    


    When I execute I get the following:
    Not enough arguments for waitpid at ./server.pl line 89, near "1)" Execution of ./server.pl aborted due to compilation errors.
      Yes, I should have stated that the code is untested. If you use waitpid(), you have to specify some flags, even if they are 0:
      waitpit(-1,0);
      Or, alternatively, just use wait:
      wait; # Yep, just like that :)
      Sorry about the mistake.

      CU
      Robartes-

        When you use waitpid, the first parm is the process id or -1 (if you just want to kill time). For the second parm: you can specify it as 0, then the call is locked; or as 1, and the call is not blocked.

        I tested that, if you give an odd number for the second parm, the call does not block; but it blocks on even number. I realized that it's a bit map, and the last bit specifies whether the call is blocked.
        Does anyone know whether the rest bits are used?