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
  Problems with "re.fullmatch" AlanT 8 245 Yesterday, 04:45 PM
Last Post: AlanT
  XML Parsing Child karthi_python 1 67 May-16-2019, 01:37 PM
Last Post: karthi_python
  Issues parsing the response from a request garnold 3 138 May-14-2019, 12:39 PM
Last Post: snippsat
  parsing logical expression with pyparsing palo173 2 77 May-13-2019, 09:22 AM
Last Post: palo173
  Read a folder with a multiple files NewBeie 7 141 May-06-2019, 08:04 AM
Last Post: NewBeie
  Problems with calculator muachihiyo 3 108 May-02-2019, 06:12 PM
Last Post: ichabod801
  folder PyQt5 created during creation exe atlass218 0 71 Apr-26-2019, 06:25 PM
Last Post: atlass218
  Converting to exe problems francisco_neves2020 12 324 Apr-20-2019, 11:58 PM
Last Post: francisco_neves2020
  Parsing Attached .MSG Files with Python3 ericl42 1 119 Apr-12-2019, 06:28 PM
Last Post: ericl42
  parsing complex text file anna 1 123 Apr-10-2019, 09:54 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)