>I am having a problem with signals. I am writing an application which
>needs to catch SIGCLDs. No problems there, BUT this same program is
>also doing a TCP/IP Accept. If this accept is interrupted by a
>SIGCLD, I want it to loop and try again, but if it is interrupted by a
>SIGTERM (which another of my processes is sending intentionally) I
>want it to stop the accept and return an error.
>When the accept is interrupted, it returns errno 4, but there is no
>way to determine what signal this was that I can find.
>So, is there any way to discover what signal was received. I am
>willing to use regular signals, OR Posix signals.
No, not if you don't install signal handlers that set flags.
int termcaught = 0;
void sigtermhandler(int sig)
termcaught = 1;
Test this flag after accept returns EINTR and reset it immediately.
An alternative solution is to install two signal handlers with
sigaction(). The first, for SIGCHLD, needs to be installed in
such a way that the system call is restarted. The second,
for SIGTERM, needs to be installed in such a way that it will
interrupt the system call. There is no portable solution to
E.g., in SunOS 4.x you would use the SA_INTERRUPT flag for the
SIGTERM handler and no flag for the SIGCHLD handler.
In SVR4/Solaris 2.x you would use SA_RESTART for SIGCHLD and no
flag for SIGTERM.