From owner-freebsd-questions Tue Sep 15 16:14:59 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA02918 for freebsd-questions-outgoing; Tue, 15 Sep 1998 16:14:59 -0700 (PDT) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from VMS.UCI.KUN.NL (vms.uci.kun.nl [131.174.64.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA02911 for ; Tue, 15 Sep 1998 16:14:54 -0700 (PDT) (envelope-from K.Staring@UCI.KUN.NL) Received: from uci.kun.nl (ops.uci.kun.nl) by VMS.UCI.KUN.NL (PMDF V5.1-10 #8798) with ESMTP id <01J1UTXHWZ74007IJC@VMS.UCI.KUN.NL> for questions@FreeBSD.ORG; Wed, 16 Sep 1998 01:14:34 +0200 (MET-DST) Date: Wed, 16 Sep 1998 01:14:31 +0200 From: Purrcat Subject: sockets, forking and zombies To: questions@FreeBSD.ORG Reply-to: K.Staring@UCI.KUN.NL Message-id: <35FEF4D7.D9D54D84@uci.kun.nl> Organization: Universitary Center for Informationprovision MIME-version: 1.0 X-Mailer: Mozilla 4.03 [nl] (Win95; I) Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'm having some trouble with a program I'm writing. After the program connects a socket to a port, and start to listen, the program should accept incoming telnets (for example) on port 4000. The program should fork and continue listening; while the child handles the connection (in the included program, say "Heyup" and close the connection). When the child is done saying "Heyup", it exits (in my example, it exits with errorcode -1, but errorcode 0 does exactly the same). But the child doesn't exit normally; it becomes a zombie. I have included a signalhandler: "(void) signal(SIGCHLD, SIG_IGN);" which should say that the parent should ignore everything the child wants to say to the parent. Still, the zombie process emerges... Does anyone know what I am doing wrong? It could be that the child tries to close a socket which it 'does not own' or something, but even if I comment these lines out, the problem stays. I'm using FreeBSD 2.2.6 (which does not really matter) and gcc (which also should not be a problem). ------------------ Program starts here ---------------------------------------- #include #include #include #include #include #include #include #include #include #include #include void dostuff(); main() { int s_in, s_out, rmtlen, bindport, pid; struct sockaddr_in lcl, rmt; /* Ignore child thingies; so no zombies emerge (NOT!) */ (void) signal(SIGCHLD, SIG_IGN); if((s_in = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("socket: %d\n", errno); exit(-1); } bzero((char *)&lcl, sizeof(lcl)); lcl.sin_family = AF_INET; lcl.sin_port = htons(4000); /* bind to port #4000 */ lcl.sin_addr.s_addr = htons(INADDR_ANY); if(bind(s_in, (struct sockaddr *)&lcl, sizeof(lcl)) < 0) { printf("bind: %d\n", errno); exit(-1); } if(listen(s_in, 5) < 0) { printf("listen: %d\n", errno); exit(-1); } /* accept loop. */ while(1) { if((s_out = accept(s_in, (struct sockaddr *)&rmt, &rmtlen)) < 0) { printf("accept: %d\n", errno); exit(-1); } if(!fork()) { close(s_in); dostuff(s_out); close(s_out); exit(-1); } close(s_out); } } void dostuff(int s) { /* write some stuff to connected port */ write(s, "Heyup..\n", 8); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message