Messages in this thread | | | Date | Thu, 26 Aug 1999 10:14:20 -0600 | From | Erik Andersen <> | Subject | Re: Async user space notification from kernel? |
| |
On Thu, Aug 26, 1999 at 03:39:44PM +0100, Tigran Aivazian wrote: > Hi, > > You just said: > > What is the best way to have the kernel notify a user space daemon > > that some event has occured without user space resorting to polling an > > ioctl(ugh)? > > > Furthermore, since /proc doesn't contain _real_ files, but auto-created > > ones, presumably a select on a /proc entry would be disappointing. > > If, by "_real_" you mean "regular" files (i.e. S_ISREG()) then using > select(2) on them is probably the most disappointing thing in the world - > i.e. it always answers "YES!" to all questions...
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 > achieve? >
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 space doesn't.
Clearly, user space could always poll the driver -- something like: /* Nasty polling */ while(1) { if (ioctl (fd, CHECK_IF_BUTTON_WAS_PUSHED) > 0) break; sleep(1); }
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
-- Erik B. Andersen Web: http://www.xmission.com/~andersen/ email: andersee@debian.org --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 majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |