LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-11-2004, 05:57 AM   #1
adoyee
LQ Newbie
 
Registered: Jul 2003
Posts: 16

Rep: Reputation: 0
CLOSE_WAIT


I write a socket program and run it at 192.168.6.19 .The machine of 192.168.1.10 run winXP.

After runnning server,telnet it and get the message.But close the telnet,processes are CLOSE_WAIT.

netstat results:

local address forein address state PID/Program
0 *:6666 *:* LISTEN 21432/server
192.168.6.19:6666 192.168.1.10:1046 CLOSE_WAIT 21432/server
192.168.6.19:6666 192.168.6.19:2687 CLOSE_WAIT 21432/server
192.168.6.19:6666 192.168.1.10:1069 CLOSE_WAIT 21432/server

What they have the same PID?


//server.c
Code:
===================================================
#include "head.h"

void sig_chld(int signo){
        pid_t pid;
        int  stat;
        pid=wait(&stat);
        printf ("child process %d has terminate\n",pid);
        return;
//end sig_chld;
}

int main(){


pid_t childpid;
int listenfd,connfd;
socklen_t childlen;
struct sockaddr_in servaddr,clientaddr;


listenfd=Socket(AF_INET,SOCK_STREAM,0);
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(PORT);

Bind(listenfd,(SA*)& servaddr,sizeof(servaddr));
Listen(listenfd,(SA*)&servaddr,LISTENQ);
signal(SIGCHLD,sig_chld);
for(1){
        childlen=sizeof(clientaddr);
        connfd=Accept(listenfd,(SA*)&clientaddr,&childlen);
        if((childpid=fork())==0){ /*Child process*/
                close(listenfd);  /*Close listen socket*/
                /*
                process the request.

                */
                writen(connfd,"Hello,world\n",sizeof("Hello,world\n"));
        close (connfd);
        exit(0);
        }
        close (childpid);        //Parent process:close connected socket
}


return 0;
}

===================================================
If delete
signal(SIGCHLD,sig_chld);
then the children processes will become zombie.

Last edited by adoyee; 02-11-2004 at 05:59 AM.
 
Old 02-12-2004, 12:18 AM   #2
adoyee
LQ Newbie
 
Registered: Jul 2003
Posts: 16

Original Poster
Rep: Reputation: 0
Helppppppppppppp
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close_wait ghodkiller Linux - Networking 0 01-08-2005 05:44 PM
Close_Wait AmitC Linux - General 0 12-30-2004 02:18 AM
CLOSE_WAIT timeout Vaish Linux - Newbie 0 02-20-2004 05:47 AM
ftp connections hanging forever in CLOSE, CLOSE_WAIT state mxyzplk Linux - Software 0 11-26-2003 10:54 AM


All times are GMT -5. The time now is 05:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration