Note that there are some explanatory texts on larger screens.

plurals
  1. POMonitoring mount point changes via /proc/mounts
    text
    copied!<p>According proc manual, one can monitor for mount point changes in linux system by opening "/proc/mounts", and adding the file descriptor to read <code>fd_set</code> in <code>select()</code> call.</p> <p>Following piece of code works on Ubuntu 9.04, and not in Ubuntu 10.04 (with 2.6.32 linux kernel):</p> <pre><code>int mfd = open("/proc/mounts", O_RDONLY, 0); fd_set rfds; struct timeval tv; int rv; FD_ZERO(&amp;rfds); FD_SET(mfd, &amp;rfds); tv.tv_sec = 5; tv.tv_usec = 0; int changes = 0; while ((rv = select(mfd+1, &amp;rfds, NULL, NULL, &amp;tv)) &gt;= 0) { if (FD_ISSET(mfd, &amp;rfds)) { fprintf(stdout, "Mount points changed. %d.\n", changes++); } FD_ZERO(&amp;rfds); FD_SET(mfd, &amp;rfds); tv.tv_sec = 5; tv.tv_usec = 0; if (changes &gt; 10) { exit(EXIT_FAILURE); } } </code></pre> <p><a href="https://gist.github.com/837605" rel="noreferrer">Compilable snippet.</a></p> <p>The file descriptor is always readable in one machine, and hence it keeps popping up in the select call. Even there are no changes in mounts.</p> <p>Am I missing something here?</p> <p>Thanks in advance for any help!</p> <p><a href="http://linux.die.net/man/5/proc" rel="noreferrer">man 5 proc:</a></p> <p>/proc/[pid]/mounts (since Linux 2.4.19)</p> <p>This is a list of all the file systems currently mounted in the process's mount namespace. The format of this file is documented in fstab(5). Since kernel version 2.6.15, this file is pollable: after opening the file for reading, a change in this file (i.e., a file system mount or unmount) causes select(2) to mark the file descriptor as readable, and poll(2) and epoll_wait(2) mark the file as having an error condition.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload