为什么以下简单的phyton代码未在android上运行?

时间:2019-03-05 22:06:25

标签: android python-3.x

我尝试在qPython3(启用了root)中运行以下代码,但它甚至没有在屏幕上显示“插入inode:”(这不是我要修理手机的作业)

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

0 个答案:

没有答案