[英]adb: Find PID from the adb shell
我正在嘗試獲取 INSIDE adb shell 進程的 PID。 所以,我正在做 adb shell,它讓我進入 android shell。 現在,如果我要使用常規外殼獲取 PID,我會使用
adb shell ps | grep android.process.acore | sed 's/\s\s*/ /g' | cut -d ' ' -f 2
或者
adb shell ps | grep android.process.acore | awk '{ print $2 }'
我得到了 PID(一個數字 - ps | grep android.process.acore
第二個字段)輸出。
但是,如果我在 android shell 中運行上述命令(在執行adb shell
),我會分別得到/system/bin/sh: sed: not found
和/system/bin/sh: awk: not found
錯誤。 這意味着,這些命令在 adb shell 中不可用。 但是,grep 有效。
ps | grep android.process.acore
的輸出ps | grep android.process.acore
adb shell
ps | grep android.process.acore
是:
XXX_x21 11826 441 502296 39028 ffffffff 4010ff6c S android.process.acore
我正在尋找數字 11826。如何在adb shell
提取它?
另外,如果有直接的方法可以在 adb shell 中獲取 PID,請提供幫助。
問候, 魯米特
從 6.0 開始的 Android 版本已經包含pidof
實用程序:
usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]...
Print the PIDs of all processes with the given names.
-s single shot, only return one pid.
-o omit PID(s)
不確定您是否可以直接獲取 PID,但是您可以嘗試以下操作
set `ps |grep android.process.acore` echo $2
這會影響將 ps 命令的輸出設置為變量 $1、$2、$3 等。PID 值在 $2 中
我試過這個,它似乎有效:
adb shell "set "ps | grep android.process.media"; kill -9 $2"
我試過這個,它似乎有效:
1. adb shell -> ps -A | grep "android.process.acore"
adb shell pidof [package name]
或者
adb shell pidof -s [package name]
-s 選項用於單發,僅返回一個 pid。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.