Asynchronous Notification
Though the combination of blocking and nonblocking operations and the select method are sufficient for querying the device most of the time, some situations aren’t efficiently managed by the techniques we’ve seen so far.
Let’s imagine, for example, a process that executes a long computational loop at low priority, but needs to process incoming data as soon as possible. If the input channel is the keyboard, you are allowed to send a signal to the application (using the `INTR’ character, usually CTRL-C), but this signaling ability is part of the tty abstraction, a software layer that isn’t used for general char devices. What we need for asynchronous notification is something different. Furthermore, any input data should generate an interrupt, not just CTRL-C.
User programs have to execute two steps to enable asynchronous
notification from an input file. First, they specify a process as the
“owner” of the file. When a process invokes the
F_SETOWN command using the
fcntl system call, the process ID of the owner
process is saved in filp->f_owner for later
use. This step is necessary for the kernel to know just who to notify.
In order to actually enable asynchronous notification, the user
programs must set the FASYNC flag in the device by
means of the F_SETFL
fcntl
command.
After these two calls have been executed, the input file can request
delivery of a SIGIO signal whenever new data arrives. The signal is sent to the process (or process group, ...