Python Forum
Problems parsing /proc folder
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?
Reply
#2
about proc: https://proc.readthedocs.io/en/latest/
Reply
#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]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 466 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  Generate lists of devices and partitions from /proc/partitions? DachshundDigital 1 730 Feb-28-2023, 10:55 PM
Last Post: deanhystad
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,390 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,436 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Python Cut/Copy paste file from folder to another folder rdDrp 4 4,944 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  Encoding problems on multiple files in one folder NikolajKorsgaard 5 3,944 Jun-11-2019, 03:39 AM
Last Post: micseydel
  Visiting invisible folders in /proc anddontyoucomebacknomore 0 1,524 Mar-18-2019, 02:05 AM
Last Post: anddontyoucomebacknomore
  Delete directories in folder is not working after folder is updated asheru93 2 2,601 Feb-13-2019, 12:37 PM
Last Post: asheru93
  copy content of folder to existing folder shlomi27 0 2,614 Aug-11-2018, 01:44 PM
Last Post: shlomi27
  execute a SQL stored proc within PYTHON PYTHONDUDE 3 9,421 Mar-21-2018, 04:15 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020