I run a sample http server in an eternal loop.
I need to close the socket after I press ^c, so I use
signal(SIGTERM,cleanEXIT);
signal(SIGINT,cleanEXIT);
Then in the top of the program.
I use :
int listenfd;
void cleanEXIT()
{
close(listenfd);
/* clean up the garbage processes*/
while(waitpid(-1,NULL,WNOHANG)>0);
printf("Byebye"
exit(0);
}
But the problem is the the socket "listenfd" did not close.
I define listenfd as a global variable.
when I open it ,as :
ptnb=atoi(argv[1]);
listenfd=socket(AF_INET,SOCK_STREAM,0);
What is wrong with my program?