Hey, what about SIGIO?
Jonathan I. Kamens
jik at athena.mit.edu
Thu Sep 27 04:44:09 AEST 1990
In article <LUSH.90Sep26102017 at athena0.EE.MsState.Edu>, lush at EE.MsState.Edu (Edward Luke) writes:
|> I would like to get a signal when new data arrives on an
|> input file descriptor, or when an output file descriptor is free to be
|> filled again. Is it possible for me to do this without using fork()
|> to start another process to monitor the file descriptor? Can I tell
|> the OS to give me a SIGIO when there is a pending condition on a
|> socket? Just what is the SIGIO signal for?
See the man page fcntl(2). You want to use the F_SETOWN fcntl call on the
file descriptor and set the ownership to your PID, and then use the FASYNC
fcntl to turn on asynchronous I/O; when ASYNC is enabled, and input comes in
on the file descriptor, your process will get SIGIO.
I'm not certain that you'll get SIGIO if there is room for writing in a
pipe; I've never used it for that, and fcntl(2) only mentions data waiting to
be read when it mentions FASYNC, so I don't know whether or not it'll work.
Oh, you'll also get SIGURG when there is an "urgent condition" on a socket;
I'm not completely sure what an "urgent condition" is, perhaps that's what
they call a premature closing of the other end of the socket or something.
One more thing -- I believe that if the other end of the FD is closed,
you'll get a SIGIO, and then when you read, you'll get 0 bytes, thus
signalling EOF.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8495 Home: 617-782-0710
More information about the Comp.unix.programmer
mailing list