Python Forum
Made a simple script for android (really simple) but it is not running
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Made a simple script for android (really simple) but it is not running
#1
Hello, people, I'm trying to run a script in Android in qPython3 (root enabled) that reads an integer "inode" and look for files in the "/proc/" folder such that this number appears in the "/proc/$pid/fd" file and gives me all the "PIDs" (an integer that represents the process in linux) found in /proc such that inode is in the /proc/pid/fd The code is fairly simple and gives me no compile errors but i can't even get the "input" to be displayed. Here is the code:

PS: how do i jump from a line to another in python tag?
import os


def getpid():
    inode = input("Insert inode:")
    # get a list of all files and directories in /proc
    procFiles = os.listdir("/proc/")
    # remove the pid of the current python process
    procFiles.remove(str(os.getpid()))  # set up a list object to store valid pids
    pids = []
    for f in procFiles:
        try:  # convert the filename to an integer and back, saving the result to a list
            integer = int(f)
            pids.append(str(integer))
        except ValueError:  # if the filename doesn't convert to an integer, it's not a pid, and we don't care about it
            pass
 
    for pid in pids:  # check the fd directory for socket information
        fds = os.listdir("/proc/%s/fd/" % pid)
        for fd in fds:  # save the pid for sockets matching our inode
            if ('socket:[%d]' % inode) == os.readlink("/proc/%s/fd/%s" % (pid, fd)):
                print("%d," % pid)
                return pid
Reply
#2
I have tried formatting your code, not totally sure if I've got all the indention correct.
it seems you have not called.
getpid()
Reply
#3
Thank you very much! It is running now
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Very Beginner question on simple variables Harvy 1 167 Apr-12-2024, 12:03 AM
Last Post: deanhystad
  Help with simple code JacobSkinner 1 313 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  No Internet connection when running a Python script basil_555 8 577 Mar-11-2024, 11:02 AM
Last Post: snippsat
Question Running Python script through Task Scheduler? Winfried 8 465 Mar-10-2024, 07:24 PM
Last Post: Winfried
  How do I organize my simple ftp modules? blobdx7 3 509 Jan-05-2024, 01:23 PM
Last Post: Gribouillis
  I must be missing something simple? SLFrey 2 515 Dec-11-2023, 03:13 PM
Last Post: SLFrey
  Help Running Python Script in Mac OS emojistickers 0 337 Nov-20-2023, 01:58 PM
Last Post: emojistickers
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 476 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Trying to make a board with turtle, nothing happens when running script Quascia 3 657 Nov-01-2023, 03:11 PM
Last Post: deanhystad
  Kivy App - Python3 script to Android app (opencv) jttolleson 7 3,475 Oct-19-2023, 01:11 PM
Last Post: MasCain

Forum Jump:

User Panel Messages

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