Grégoire Welraeds wrote:
> Ok my problem goes like this :
> i'm, at the present time, writing a concurrent server communicating
> with his clients through TCP/IP. One part of the code is :
> if signal(SIGCHLD, sighandler) < 0
> {
> ...
> }
> ...
> socket(...); /* those are classics */
> bind(...);
> Listen(...);
> while (1)
> {
> if ((sd = accept(...)) < 0)
> {
> printf("accept error\n");
> /* i have to go on since its a concurrent server */
> }
> ....
> if ((pid = fork()) == 0)
> {
> /* child process */
> }
> }
> I use the SIGCHLD handling to maintain a table of the running childs.
> But when a child finish, (SIGCHLD is delivered to the father process)
> he send me thousand "accept error" until i kill (-9) the father process.
You should only fork() a child process if the accept() is successful.
Otherwise, you should use `continue' to skip the rest of the loop.
It would probably be better to use sigaction() with the SA_RESTART
flag, so that the accept() call isn't interrupted by signals. You
probably also want to use the SA_NOCLDSTOP flag, so that you don't get
a SIGCHLD if a child process is suspended.
--
Glynn Clements <[EMAIL PROTECTED]>