There should be methods on Unix and Linux using select or something
like that.  At least Unix and Posix provide the functionality you are
asking already at OS-level, so it is just a matter of if and how to
access this from Ruby.  I would prefer this OS-dependent approach.