Python Forum

Full Version: Problems parsing /proc folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to make a code that searches for an integer inode in the /proc files of the form /proc/pid and returns what files have this integer. When I made the code I did not know /proc couldn't be parsed by normal means (my script returns Errno13 permission denied even with root enabled on qpython3) only now I know there is the pip package "proc" but I have not found much information about this package online and I don't know if it applies here.

Here is where my code freezes
fds = os.listdir ("/proc/%s/fd" % pid)
        for fd in fds:
            if ('socket:[%d]' % inode) == os.readlink ("/proc/%s/fd/%s" % (pid, fd)):
                print ("%s, " % pid)
when I try to create variable fds receiving the list of folders inside "/proc/pid/fd".Anyone knows how to fix it?
deadeye@nexus ~ $ for path in pathlib.Path('/proc/').glob('*/fd/*'): 
.................     if not path.name.isdigit(): 
.................         continue 
.................     abs_path = path.resolve() 
.................     if abs_path.name.startswith('socket'): 
.................         print(path, '->', abs_path.name) 
.................            
Output:
/proc/10824/fd/3 -> socket:[19977] /proc/10824/fd/4 -> socket:[19971] /proc/10824/fd/5 -> socket:[19982] /proc/10824/fd/6 -> socket:[19988] /proc/32720/fd/1 -> socket:[110706] /proc/32720/fd/2 -> socket:[110706] /proc/32720/fd/5 -> socket:[108729] /proc/32720/fd/7 -> socket:[108730] /proc/32720/fd/8 -> socket:[110709]