Bottom Page

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
Quote
#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()
Quote
#3
Thank you very much! It is running now
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  running script from CLI in windows aster 6 163 Yesterday, 07:10 PM
Last Post: aster
  Adding second message to simple loop error PythonGainz 2 95 Apr-06-2020, 11:55 AM
Last Post: PythonGainz
  Simple cards game blackpanda 1 185 Apr-02-2020, 05:02 PM
Last Post: newyawksupreme
  Iterate through all files in a folder and make simple calculation danielappleton 2 80 Apr-01-2020, 09:57 AM
Last Post: danielappleton
  Not able to crack a simple visualization – missing something basic – plz guide darpInd 4 112 Mar-27-2020, 09:26 AM
Last Post: darpInd
  Problem running script within console koepjo 3 144 Mar-26-2020, 07:11 AM
Last Post: koepjo
  Simple question concerning python dot notation. miner_tom 1 63 Mar-24-2020, 05:20 PM
Last Post: buran
  Beginner - simple package installation error mefeng2008 0 216 Mar-13-2020, 09:17 AM
Last Post: mefeng2008
  Simple python code error cls0724 5 298 Mar-12-2020, 07:45 PM
Last Post: stullis
  simple login problem MMOToaster 2 247 Feb-25-2020, 09:28 AM
Last Post: MMOToaster

Forum Jump:


Users browsing this thread: 1 Guest(s)