简体   繁体   中英

linux, inotify - how to subscribe?

Can you please explain me the inotify mechanism? I've searched in the web about it, but what I understood 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM