Applications often need to block on more than one file descriptor. Whithout the aid of threads, a single process can’t even dream on blocking on more than one file descriptor at the same time. The thing is that working with multiple file descriptors is fine, so long as they are always ready to be read from or written to. But as soon as one file descriptor that is not yet ready is encountered - say, if a read() system call is issued, and there is not yet any data — the process will block, no longer able to service the other file descriptors. And this, we all know, can be a pain in the ass sometimes.
Here’s a real world example. Imagine blocking on a file descriptor related to interprocess communication while stdin has data pending. The application won’t know that keyboard input is pending until the blocked IPC file descriptor ultimately returns data - but what if the blocked operation never returns?
Read More