Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems parsing /proc folder
#1
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?
Quote
#2
about proc: https://proc.readthedocs.io/en/latest/
Quote
#3
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]
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Parsing Large Numbers Question amyvaulhausen 5 177 Yesterday, 08:46 AM
Last Post: samsonite
  problems with the If statement or is it the variables being used NickIgoe 2 56 Mar-22-2019, 06:34 AM
Last Post: NickIgoe
  parsing xml and outpur as csv kentck86 1 86 Mar-18-2019, 02:10 PM
Last Post: snippsat
  Visiting invisible folders in /proc anddontyoucomebacknomore 0 46 Mar-18-2019, 02:05 AM
Last Post: anddontyoucomebacknomore
  Parsing an MBOX file Oliver 0 52 Mar-14-2019, 07:49 PM
Last Post: Oliver
  unexpected EOF while parsing whatloop 3 137 Mar-09-2019, 06:59 PM
Last Post: whatloop
  parsing xml josesalazmit 1 86 Mar-05-2019, 02:20 AM
Last Post: scidam
  Problems with For Loops and Lists Sagramor72 2 116 Mar-04-2019, 01:26 PM
Last Post: Sagramor72
  problems with random number/string PrasadPython 3 106 Mar-01-2019, 06:00 PM
Last Post: ichabod801
  parsing local xml files to csv erdem_ustunmu 8 291 Feb-27-2019, 12:37 PM
Last Post: erdem_ustunmu

Forum Jump:


Users browsing this thread: 1 Guest(s)