linux, inotify - how to subscribe?
Can you please explain me the inotify mechanism? I’ve searched in the web about it, but what I understoo开发者_JS百科d is that if I want to see the changes in a file I have to do polling with the “read” function. Is there any callback function which will notify me when the file has a change without polling?
Thanks,
I'm speculating that you are using some GUI library that handle events for you.
The better GUI libraries have a way to watch file descriptors. In GTK, it is gtk_input_add_full; in Qt, QSocketNotifier might work for you.
The inotify calls employ file descriptors. Rather than polling you can use the returned FDs in the select() family of calls. It's not exactly a callback function but reduces the overhead you are concerned with.
You can use the ev_io part of the libev library. This will allow you to set a callback for when the inotify fd is readable.
The documentation for libev can be found here: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod
No, inotify requires polling.
Registering a callback using signal (as suggested), is IMO worse then doing regular polling.
精彩评论