Re: Problem with killing zombie processes

From: Gordon Burditt (gordonb.dsl5o_at_burditt.org)
Date: 05/03/05

  • Next message: James Antill: "Re: threads & sockets"
    Date: Tue, 03 May 2005 15:53:36 -0000
    
    

    >I am writing a client/server program. The server is being implemented
    >as a concurrent server(using the fork), where it handles multiple
    >clients simultaneously.
    >
    >Now what I require, is that when a client closes up a connection with
    >the server, the process that was handling the client is terminated and
    >cleaned up from the system.
    >
    >At the begining of the program, I am calling the following:
    >(void) signal(SIGCHLD, kill_dameon);

    A SIGCHLD signal handler needs to call wait(), or one of its variants,
    to bury the child.

    >
    >The kill_dameon method, that clears up zombie processes is the
    >following:
    >void kill_dameon(int sig)
    >{
    > pid_t pid;
    > int data;
    >
    > data = 1;
    > if (pid == -1)
    > error_msg();
    >
    > printf("Cleared a zombie process.\n");
    >} // end method kill_dameon
    >
    >Now when client and server programs are exectued, when the first
    >client terminates, the message(Cleared a zombie process.\n) given in
    >method is shown on server. When the second, third, etc client
    >terminates, that message is not given any more.
    >
    >I added this line "(void) signal(SIGCHLD, kill_dameon);" at the end of
    >the kill_dameon method, but when did this, after first client
    >terminates, an infinite loop of that message was made.

    SIGCHLD is given not for a child dying, but for having a dead,
    unburied, child. If you don't call wait() or one of its variants
    in the signal handler, it will loop. If you want to make absolutely
    sure you don't pause waiting for a child, use wait3() or wait4()
    with the WNOHANG option.

                                                    Gordon L. Burditt


  • Next message: James Antill: "Re: threads & sockets"

    Relevant Pages

    • Re: What doesnt lend itself to OO?
      ... >> proxy and instructs the server to constuct the real object. ... rather than client code. ... If 'clock' is instantiated in the server, ... > for the server interface at the OOA level. ...
      (comp.object)
    • This is going straight to the pool room
      ... or not the client has privilege to do what they're trying to do, ... The server environment is this: ... 3GL User action Routines that Tier3 will execute on your behalf during the ... Routine Name: USER_INIT ...
      (comp.os.vms)
    • [Full-Disclosure] R: Full-Disclosure Digest, Vol 3, Issue 42
      ... Full-Disclosure Digest, Vol 3, Issue 42 ... SD Server 4.0.70 Directory Traversal Bug ... Arkeia Network Backup Client Remote Access ...
      (Full-Disclosure)
    • Re: What doesnt lend itself to OO?
      ... > rather than client code. ... no way to do that without also touching the object with clock semantics ... will not encapsulate both clock semantics and network semantics. ... The server can do whatever it wants ...
      (comp.object)
    • RE: Fax monitor incoming + outgoing calls?
      ... problem between the client computer and the SBS server. ... Client is using the internal IP address of the SBS server as the ... To the folder redirection GPO issue: ...
      (microsoft.public.windows.server.sbs)