How to monitor for new mounts on Linux (without polling)

(Comments)

When I was googling for this it was quite to hard to find so I thought I'd share. /proc/mounts doesn't publish a stream of events or something like that, the trick is to put the file in the "exceptfds" field. A "special exception" is triggered when it's updated and you can read it from scratch.

import select
f = open("/proc/mounts")
while True:
    r,w,x = select.select([],[],[f])
    f.seek(0)
    print f.read()

Of course this can be combined with select/epoll on other fds if you actually look at the return value. :-)

Current rating: 5

Comments

Recent Tweets


Recent Posts

Archive

2018
2016
2015

Categories

Tags

Authors

Feeds

RSS / Atom