3

Are there documented standards for the semantics of Linux /proc/sys file descriptors?

Is it proper to use seek(0) on them?

Here's a piece of code which seems to work fine for my tests:

#!/usr/bin/python
from time import sleep
with open('/proc/sys/fs/file-nr','r') as f:
    while True:
        d = f.readline()
        print d.split()[0]
        f.seek(0)
        sleep(1)

This seems to work. However, I'd like to know if that's the right way to do such things or if I should loop over open() ... read() ... close()

In this particular case I'll be using this with the collectd Python plugin ... so this particular code would be running indefinitely in a daemon. However, I'm interested in the answer for the general class of questions.

(Incidentally is there an "open files/inodes" module/plugin for collectd)?

Jim Dennis
  • 17,054
  • 13
  • 68
  • 116

1 Answers1

3

Yes, it is proper to use lseek(2) and fseek(3) on files on proc pseudo-file system. Calls which aren't appropriate will result and error, thus if python seek (calling presumably lseek/fseek underneath) works, it's appropriate.