AFAIK ignoring SIGCHILD with signal(SIGCHILD,SIG_IGN); 
is enough to prevent zombies.

 - Erwin


Leechow wang wrote:
> 
> Hi,all,
> I wrote a simple listening socket program.The father forks the two child
> progresses.One is reporting the status of the system;the other is dealing
> with the network service --just dealing with the client requirement through
> the network. I use the signal function to deal with the child progress. But
> when it run,it creates too many zombie progresses.I don't what's the
> problem. Could anyone give me a hand? the below is my code:
> 
> void sig_chld(int sig)
> {
> pid_t pid;
> int stat
> while((pid=waitpid(-1,&stat,WNOHANG)) >0);
> return;
> }
> 
> main ()
> {
> ...
> signal(SIGCHLD,&sig_chld);/*dealing the child progress*/
> if (!fork()){
> /* Reading the status of the system*/
> }
> 
> while(1)
> {
> sin_size = sizeof(struct sockaddr_in);
> new_fd=accept(sock_fd,(struct sockaddr *)&their_addr,&sin_size));
> if (!fork())    {
> /*the child progress deals with the network requirment
> ...
> */
> close(new_fd);
> exit(0);
> }
> else
> {
> 
> }
> }
> close(sock_fd);
> exit(0);
> }
> 
> Thanks in advance!
> 
> Lichow
> 
> ______________________________________________
> FREE Personalized Email at Mail.com
> Sign up at http://www.mail.com/?sr=signup
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> --
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/rtlinux/
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to