Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site wlbr.UUCP Path: utzoo!watmath!clyde!akgua!sdcsvax!bmcg!cepu!trwrba!trwrb!scgvaxd!wlbr!jm From: jm@wlbr.UUCP Newsgroups: net.unix-wizards Subject: Re: problems with alarm(0) Message-ID: <173@wlbr.UUCP> Date: Fri, 25-May-84 17:33:24 EDT Article-I.D.: wlbr.173 Posted: Fri May 25 17:33:24 1984 Date-Received: Fri, 1-Jun-84 21:07:32 EDT References: <179@philmds.UUCP> Organization: Eaton ES, Westlake Village, CA Lines: 35 x johan@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