According to epoll(7), you create an epoll instance, register file descriptors with epoll_ctl, and wait with epoll_wait, which returns only the descriptors that are ready. It is Linux-only; macOS and the BSDs have kqueue.