Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.questions Subject: Re: How does one imitate SV_INTERRUPT? Message-ID: <11847.Jun1621.03.3791@kramden.acf.nyu.edu> Date: 16 Jun 91 21:03:37 GMT References: <13619@mentor.cc.purdue.edu> Organization: IR Lines: 22 In article <13619@mentor.cc.purdue.edu> woodcock@mentor.cc.purdue.edu (Bruce Sterling Woodcock) writes: > The subject basically says it all. I'm programming on a Sequent Symmetry > using Dynix V3.0.12 which, unfortunately, doesn't support the SV_INTERRUPT > flag. Most systems after 4.2BSD have it. To quote a 4.3BSD manual page: One of BSD 4.2's biggest failures was forcing system calls to restart; there are just too many applications where EINTR can't be ignored. Your best bet is to use non-blocking I/O with select(). To force select() to terminate, have it check readability on an empty pipe; inside the signal handler, write a byte to the pipe, and read it back after the select(). (If you're worried about the possibility of receiving a few thousand signals before the pipe is read, keep a global flag which says whether the pipe is empty or not. Don't write unless the pipe is empty. Clear the flag when you read the pipe. Make sure to set sv_mask so that you don't have two signal handlers running at once.) If all you want to do is wait for a signal to arrive: Create a pipe. Set a flag to 0. Read one byte from the pipe; this will block. Inside the signal handler, if the flag is 0, set it to 1 and write one byte to the pipe. Once the byte has been read, close the pipe and continue. ---Dan