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

(0 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

There are currently no comments

New Comment

required

required (not published)

optional

Recent Tweets

  • Fredrick Rybarczyk

    Fredrick Rybarczyk @Fredrick_R

    Ernst Sjöstrand

    SLUTA skriva som om lärarbehörighet vore en särskilt relevant. Våra elever måste få träffa lärare med ämneskunskape… https://t.co/VYMawBky4O
    1 day, 10 hours ago

  • Myq Kaplan

    Myq Kaplan @myqkaplan

    Ernst Sjöstrand

    TRUMP: Mexicans are bad TRUMP: Muslims are bad TRUMP: Media are bad EVERYONE: what about Nazis TRUMP: let's not single anyone out
    2 days, 5 hours ago

  • Åsa Schwarz

    Åsa Schwarz @AsaSchwarz

    Ernst Sjöstrand

    Regeringen börjar nu använda Sveriges tunga kompetens inom cybersäkerhet rätt. @amelsec tillträder som styrelsemedlem hos Trafikverket. =>
    1 week ago


Recent Posts

Archive

2016
2015

Categories

Tags

Authors

Feeds

RSS / Atom