problems with alarm(0)
jm at wlbr.UUCP
jm at wlbr.UUCP
Sat May 26 07:33:24 AEST 1984
x
johan at philmds complains that bracketing a read/write with alarm()s
may fail because the SIGALRM may come in even after an alarm(0) call.
My customary way of preventing this is to ignore the SIGALRM before
calling alarm(0).
onalarm()
{
signal(SIGALRM, onalarm);
alarm(2);
A:
}
{
...
signal(SIGALRM, onalarm);
alarm(2);
B:
i = read(fd, buf, sizeof(buf));
ADDED LINE>>>> signal(SIGALRM, SIG_IGN);
alarm(0);
if (i == -1 && errno == EINTR) {
... /* handle timeout */
} else {
... /* handle data read */
}
...
}
In this manner, even if the SIGALRM is given to the process, it will do
no harm.
Jim Macropol
{scgvaxd,ihnp4,trwrb,vortex}!wlbr!jm
More information about the Comp.unix.wizards
mailing list