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 signalling ability is part of the tty layer, which isn’t attached to 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. The user ID of a file’s
owner is stored in filp->f_owner
by the fcntl system call
when an application invokes the F_SETOWN
command.
Additionally, the user programs
must set the FASYNC
flag in the device by
means of another fcntl in order to actually enable asynchronous
notification.
After these two calls have been executed, the input file
generates a SIGIO
signal whenever new data arrives. The
signal is sent to the process (or process group, if the value is negative)
stored in filp->f_owner
.
For example, the following lines enable asynchronous notification to ...
Get Linux Device Drivers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.