Search code examples
androidfileobserver

FileObserver not working for /proc/net/tcp6


I want to monitor /proc/net/tcp6 file and to do that efficiently with FileObserver, however for some unknown reason onEvent() callback never called.

    observerTcp6 = new FileObserver("/proc/net/tcp6", FileObserver.ALL_EVENTS) {
        @Override
        public void onEvent(int event, String path) {
            Log.i("TAG", "onEvent");
        }
    };
    observerTcp6.startWatching();

With regular File class parsing this files works perfect. Could anyone help me here? :)


Solution

  • The reason of your failure is that /proc/net/tcp6 is not really a file ;-)

    It only looks like a file (ex., you can "open" and "read" it), but actually whole /proc/* entries are an interfaces to various kernel statistics\data, represented as "pseudo-files" only for simplifying access to them.

    So, you can not use any other file methods on them, except "open" and "read".

    P.S. Your question is Linux related one, not actually Android.