# adv reqd on SIGCHLD on accept call

**URL:** <https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572>\
**Category:** Programming\
**Created:** [July 23, 2006, 12:03am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572 "2006-07-23T00:03:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenjagan](https://community.unix.com/letter_avatar/stevenjagan/32/6_22734026db12803ebb3e059622ac3534.png) [@stevenjagan](https://community.unix.com/u/stevenjagan)\
**Post date:** [July 23, 2006, 12:03am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/1 "2006-07-23T00:03:03Z")

</div>

Hi,

I have small problem.

In my (concurrent)server programm,  
I am handling accept problem from client like this.

sample of server code.  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

end = 0;  
while (! end )  
{  
sockfd = accept(...)  
if(sockfd == -1)  
{  
if (errno == EINTR) /\* this is bcoz of SIGCHLD recvd from child  
_/  
{  
continue;  
}  
else  
/_ display error and come out\*/  
{  
end = 1;  
}  
}  
else  
{  
/\* continue further ..........._/  
}  
}  
/_\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

Is there any way to catch where the error is occuring in the client  
process?  
(like the line number / or suggest any debugging procedure)

Pl adivce me..

--  
Jagannath Desai

---

<div class="post-metadata">

**Author:** ![matrixmadhan](https://community.unix.com/letter_avatar/matrixmadhan/32/6_22734026db12803ebb3e059622ac3534.png) [@matrixmadhan](https://community.unix.com/u/matrixmadhan)\
**Post date:** [July 23, 2006, 2:51am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/2 "2006-07-23T02:51:57Z")

</div>

use code tags,

```nohighlight
end = 0;
while (! end )
{
	sockfd = accept(...)
	if(sockfd == -1)
	{
		if (errno == EINTR) /* this is bcoz of SIGCHLD recvd from child 
		*/
		{
			continue;
		}
		else
		/* display error and come out*/
		{
			end = 1;
		}
	}
else
{
/* continue further ...........*/
}
}

```

i could not find the corresponding if to the else  
the else with continue further...

is the above just a snippet

---

<div class="post-metadata">

**Author:** ![stevenjagan](https://community.unix.com/letter_avatar/stevenjagan/32/6_22734026db12803ebb3e059622ac3534.png) [@stevenjagan](https://community.unix.com/u/stevenjagan)\
**Post date:** [July 23, 2006, 3:15am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/3 "2006-07-23T03:15:22Z")

</div>

yes ..  
it is a sample part of my server code ..  
if child gets killed abruptly then in my server (which is parent process)program, i am checking for EINTR.  
but i wanted to check in detail where in my child process, this is happening.

---

<div class="post-metadata">

**Author:** ![stevenjagan](https://community.unix.com/letter_avatar/stevenjagan/32/6_22734026db12803ebb3e059622ac3534.png) [@stevenjagan](https://community.unix.com/u/stevenjagan)\
**Post date:** [July 23, 2006, 3:24am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/4 "2006-07-23T03:24:25Z")

</div>

in trace file, am getting error msgs like this..

\>\>\>\>\>\>\>\>\>\>\>\>\>  
Server : accept error (4)  
Server : SIGCHLD received  
\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>

.  
.  
here (4) means EINTER .. right ..

---

<div class="post-metadata">

**Author:** ![stevenjagan](https://community.unix.com/letter_avatar/stevenjagan/32/6_22734026db12803ebb3e059622ac3534.png) [@stevenjagan](https://community.unix.com/u/stevenjagan)\
**Post date:** [July 28, 2006, 2:05am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/5 "2006-07-28T02:05:25Z")

</div>

Hi,  
finally I got some reasonable trace by using truss command in AIX .  
syntax is ..  
truss -d -f -p -o jj\_trc 5054664

where,  
5054664 is the parent pid, on which i did the trace.  
jj\_trc is the output trace file  
-f forces to trace on the childs

I also attached the trace file.  
I am triying to find the cause..  
Any body simultaneously also can check..

and this is how I handling the signal..

```nohighlight
static void trtCHLD(int X)                                                      
{
        int status ;
        pid_t ret_pid;
        fprintf( stderr, " ***SIGNAL SIGCHLD RECEIVED*** \n");
        while ((ret_pid = waitpid((pid_t) -1,(int *) &status ,WNOHANG | WUNTRACED)) > 0);                                                                       

if (ret_pid > 0)
{
  if (WIFEXITED(status)) {
    fprintf(stderr, "Child exited with RC=%d\n", WEXITSTATUS(status));          
  }
  if (WIFSIGNALED(status)) {
    fprintf(stderr, "Child exited via signal %d\n", WTERMSIG(status));          
  }
}
         signal(SIGCHLD,trtCHLD);
         return;                 
 }

```

and calling this fn in the server..

```nohighlight
signal(SIGCHLD,trtCHLD);

```

before the accept call..

but in the traces files I am not finding any messages getting printed as used in the file.  
Is there any changes reqd for the arguements to waitpid function?

Pl any body can have a look at the trace file (generated using truss command) attached in my prev. posting and suggest me on this...

waiting for reply.................

---

<div class="post-metadata">

**Author:** ![jamaal.d](https://community.unix.com/letter_avatar/jamaal.d/32/6_22734026db12803ebb3e059622ac3534.png) [@jamaal.d](https://community.unix.com/u/jamaal.d)\
**Post date:** [July 28, 2006, 7:24am UTC](https://community.unix.com/t/adv-reqd-on-sigchld-on-accept-call/163572/6 "2006-07-28T07:24:40Z")

</div>

[quote=stevenjagan]  
Hi,

I have small problem.

In my (concurrent)server programm,  
I am handling accept problem from client like this.

sample of server code.  
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

end = 0;  
while (! end )  
{  
sockfd = accept(...)  
if(sockfd == -1)  
{  
if (errno == EINTR) /\* this is bcoz of SIGCHLD recvd from child  
_/  
{  
continue;  
}  
else  
/_ display error and come out\*/  
{  
end = 1;  
}  
iavpbmwtvdo
