It is sometimes thought that exceptfds is needed to detect errors, but that is a misconception. Errors will be flagged in readfds. Although POSIX requires it (and even calls the parameter errorfds), it depends on the OS whether errors are also flagged in exceptfds. Really, this parameter is only needed if you care about exceptional conditions, but only rarely is there any need to detect those.
What qualifies as an exceptional condition depends on the kind of file descriptor, but by far the most common use is on a TCP socket where it indicates that out-of-band data is available to be read using recv()
with the MSG_OOB
flag. However, TCP out-of-band data has a number of quirks (e.g. only 1 byte can be outstanding) and as a result is rarely used.
In recent Linux kernels exceptfds can be used to detect when certain sysfs attributes change. The current value of the attribute can be read by reading the appropriate file under /sys
, and a select()
on the file descriptor will flag exceptfds when the attribute changes. However this currently only works for some of the attributes, and for mount changes (/proc/mounts
).
Also some device drivers will flag certain device-specific conditions using exceptfds.