How to get signal interrupt on file descriptor ?

Jonathan I. Kamens jik at athena.mit.edu
Mon Apr 29 16:41:18 AEST 1991


  You need to use three different fcntl() calls on each file descriptor for
which you want to get SIGIO.  First, do an F_SETOWN to set the process ID or
process group that should get the signal when input is available.  Then, do an
F_GETFL to get the current descriptor flags, add FASYNC to the flags (or it
in), and use F_SETFL to set the flags to the new value.

  If you can pretty much be sure which flags are set on the file descriptor to
begin with, or if you don't care what flags were set to begin with and want a
specific set of flags on the file, you don't need to do the F_GETFL -- just
use F_SETFL to set the flags you want.

  See the man page for fcntl(2) for more information about all of this.

  Note that once you get the SIGIO, your signal handler should *not* try to do
anything complex like read data and do stuff with it, unless you can be
ABSOLUTELY CERTAIN that everything you're doing in the handler is reentrant. 
Instead, your signal handler should set a flag that your program should check
regularly (assuming that your program works in a command loop or that it is
hung in a system call that will be interrupted when the signal is received, or
something like that) to see if input is pending.

  Note also that the signal doesn't tell you which descriptor has input
pending, so you have to check all of the descriptors thave have SIGIO enabled,
using select() or something, when you get the signal.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710



More information about the Comp.unix.programmer mailing list