I use FileObserver to monitor '/proc/net/arp' directory,but I can't get any event in onEvent method.The code is below:
public class MyFileObserver extends FileObserver{
private Set<OnClientConnectListener> mListeners;
private boolean mWatching = false;
public MyFileObserver(String path) {
super(path);
}
@Override
public void onEvent(int event, String path) {
Log.d("conio","event:"+event+" , path:"+path);
switch(event) {
case FileObserver.MODIFY:
Log.d("conio","event modify");
ArrayList<String> ips = WifiHelper.getClientList(true, 3000);
if(mListeners != null) {
for(OnClientConnectListener lis : mListeners) {
lis.onConnectChange(ips);
}
}
break;
}
}
How could I monitor '/proc/net/arp', I checked it has read perssion for this file , and I can use FileInputStream to read data from it.
File observer is based on inotify mechanism, however, /proc is not generic file system. All the 'file' is just a interface to the kernel, through which you can get/set information from/to kernel. All the content is generated on the fly. That is why inotify is not work on /proc system. Please refer to this page.
However, users of Ubuntu 13.04 state that this works fine. Maybe the newest kernel supports such facility. I have copied the post here, the original page is here.
Compile the following program (inotifyerr.c)
gcc inotifyerr.c
Tested this on Ubuntu 13.04 and it is working fine:
Using inotifywait on /proc works fine too