Select(2) on /proc is indeed disappointing -- it does nothing
useful. For example, I wrote a simple test app that did a select on
/proc/net/arp and left it running in window A. In window B, I did a 'cat
/proc/net/arp' and it showed only 2 entries. Then in windows B, I did
a 'ping 255.255.255.255', so now a 'cat /proc/net/arp' showed lots of
entries. Unfortunatly, in windowA, select was still sleeping, unaware
that the file had "changed". This is, presumably, because there isn't
really a file there, just some text that was generated on read.
> Seriously though, the answer to your question depends on what kind of
> event your userspace daemon wants to be notified about. For example, if
> the event is the fact of some time being elapsed, the best way to be
> notified of this is to use alarm(2) system call and catch SIGALRM (or
> setitimer(2)). If the event is a death of a child then you must catch
> SIGCLD (and of course beware of subtle SIGCLD semantics). etc etc.
> Therefore, perhaps it is worth being more specific about what you want to
Imagine a hardware device with a big red button on the front that is
connected to a linux box that has a nice linux device driver. A person
(in the real world) walks up to the device and pushes the big red
button. On the computer, there is a user space application that dearly
wants to know if that button ever gets pushed so it can change state and
do the Right Thing(tm), software wise.
The Linux device driver can easily be notified asyncronously when the
button is pushed. It sits silently waiting till the button is pushed. So
now the device driver knows something interesting has happened, but user
Clearly, user space could always poll the driver -- something like:
/* Nasty polling */
if (ioctl (fd, CHECK_IF_BUTTON_WAS_PUSHED) > 0)
This is obviously a bad solution. Another way to do this would be for
user space to expect the kernel to block in the ioctl. This would also
be bad, bad, bad, since it would create an unkillable process (ioctls
are not interruptable last I checked).
So my question boils down to: How can user space find out asyncronously
when a button gets pushed, without resorting to ugly stuff like polling?
Again, please CC me directly since I'm not currently subscribed.
-- Erik B. Andersen Web: http://www.xmission.com/~andersen/ email: email@example.com --This message was written using 73% post-consumer electrons--
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to firstname.lastname@example.org Please read the FAQ at http://www.tux.org/lkml/