getting notified on flock/lockf/fcntl changes without polling
Asked Answered
H

0

8

Is there a way (in Linux) of getting updates on the lockedness status of a file without polling?

I know that the status can be polled via a lockf(fd, F_TEST) or speculative LOCK_NB|LOCK_SH, but polling is bad(tm).

Of course, finding out when a file is NOT locked can be done with a simple lock attempt, but I want to sample the other edge too (use-case: a (large) program uses lockf to synchronize between instances - I can probably get it changed to flock, and I want to add a GUI that displays when the lock is acquirable, of course while not hogging the lock).

Note that inotify does not work in this case, at least on linux 3.9.1.

Harryharsh answered 11/9, 2013 at 15:38 Comment(3)
I'm curious why inotify does not work in this case. Does locking a file require accessing it or changing its attributes, and wouldn't you get a callback if that happened?Dynasty
inotify does not send you an event when the file is locked - only when it is opened.Harryharsh
I think this is available via dnotify.Spruik

© 2022 - 2024 — McMap. All rights reserved.