找到手机正在执行的shell脚本

本文介绍了一种通过adb命令在指定Android设备上查找并获取Shell进程PID的方法。该方法利用Python的subprocess模块执行adb命令,从命令返回结果中解析出目标Shell进程的PID。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#coding:utf-8
import os
import subprocess

def get_shell_pid(self):
        sh_pid=""
        findpid_command = 'adb -s '+self.m_device+' shell ps |findstr "sh" '
        self.logger.info(self.m_device)
        p = subprocess.Popen(findpid_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        returnValue= p.communicate()[0]
        self.logger.info("shellpid info:%s"%returnValue)
        pidlist = returnValue.split("\n")
        for loop in range(len(pidlist)):
            if " sh\r" in pidlist[loop]:
                self.logger.info(pidlist[loop])
                self.logger.info("find shell process")
                sh_pidinfo = pidlist[loop]
                self.logger.info("sh_pidinfo:%s"%sh_pidinfo)
                pidinfo_list = sh_pidinfo.split()
                sh_pid=pidinfo_list[1]
                self.logger.info("sh_pid is:%s"%sh_pid)
                break
        else:
            self.logger.info("can not find shell process")
        return sh_pid

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值