Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.programmer Subject: Re: How to get signal interrupt on file descriptor ? Message-ID: <1991Apr29.064118.7082@athena.mit.edu> Date: 29 Apr 91 06:41:18 GMT References: <1991Apr28.131258.25761@eik.ii.uib.no> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 31 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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710