Python Forum
Problems parsing /proc folder - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problems parsing /proc folder (/thread-16605.html)



Problems parsing /proc folder - anddontyoucomebacknomore - Mar-06-2019

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?


RE: Problems parsing /proc folder - Larz60+ - Mar-06-2019

about proc: https://proc.readthedocs.io/en/latest/


RE: Problems parsing /proc folder - DeaD_EyE - Mar-06-2019

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]