android檢視當前手機中的程序
阿新 • • 發佈:2019-01-09
正常情況下,每一個Android應用啟動後都會對應一個程序,當前越來越多應用會有多個程序,為了推送,為了記憶體,或者為了保活。如何檢視應用程序呢。
1.DOS下面cmd,然後開啟adb shell,直接ps命令,顯示當前手機所有程序,如圖所示:
2.利用(ps|grep 條目名稱)命令,過濾自己需要的程序,比如列出條目裡含有tencent字元的程序(包名裡面含有該字元),則輸入ps|grep tencent,如圖所示則,QQ包含的程序下面幾個:
各列引數意義:
USER 程序當前使用者;
PID Process ID,程序ID;
PPID Process Parent ID,程序的父程序ID;
VSIZE Virtual Size,程序的虛擬記憶體大小;
RSS Resident Set Size,實際駐留”在記憶體中”的記憶體大小;
WCHAN 休眠程序在核心中的地址;
PC Program Counter;
NAME 程序名;
3.還有比較重要的兩個是程序的Importance等級以及adj值,關於這兩個定義大家可以不必深究,但是要有一定的理解,這兩個玩意是具體決定了系統在資源吃緊的情況下該殺掉哪些程序。通過cat /proc/程序id/oom_adj可以看到當前程序的adj指,比如輸入cat /proc/32366/oom_adj
cat檢視程序的adj值後我們會得到其返回結果“0”,說明當前程序正位於前臺,因為我的手機qq是開啟的。
同樣,我按home鍵,把qq退到後臺,這個時候,再輸入cat /proc/32366/oom_adj,則如下結果
而adj值則在ProcessList中定義:
final class ProcessList {
// OOM adjustments for processes in various states:
// Adjustment used in certain places where we don't know it yet.
// (Generally this is something that is going to be cached, but we
// don't know the exact value in the cached range to assign yet.)
static final int UNKNOWN_ADJ = 16;
// This is a process only hosting activities that are not visible,
// so it can be killed without any disruption.
static final int CACHED_APP_MAX_ADJ = 15;
static final int CACHED_APP_MIN_ADJ = 9;
// The B list of SERVICE_ADJ -- these are the old and decrepit
// services that aren't as shiny and interesting as the ones in the A list.
static final int SERVICE_B_ADJ = 8;
// This is the process of the previous application that the user was in.
// This process is kept above other things, because it is very common to
// switch back to the previous app. This is important both for recent
// task switch (toggling between the two top recent apps) as well as normal
// UI flow such as clicking on a URI in the e-mail app to view in the browser,
// and then pressing back to return to e-mail.
static final int PREVIOUS_APP_ADJ = 7;
// This is a process holding the home application -- we want to try
// avoiding killing it, even if it would normally be in the background,
// because the user interacts with it so much.
static final int HOME_APP_ADJ = 6;
// This is a process holding an application service -- killing it will not
// have much of an impact as far as the user is concerned.
static final int SERVICE_ADJ = 5;
// This is a process with a heavy-weight application. It is in the
// background, but we want to try to avoid killing it. Value set in
// system/rootdir/init.rc on startup.
static final int HEAVY_WEIGHT_APP_ADJ = 4;
// This is a process currently hosting a backup operation. Killing it
// is not entirely fatal but is generally a bad idea.
static final int BACKUP_APP_ADJ = 3;
// This is a process only hosting components that are perceptible to the
// user, and we really want to avoid killing them, but they are not
// immediately visible. An example is background music playback.
static final int PERCEPTIBLE_APP_ADJ = 2;
// This is a process only hosting activities that are visible to the
// user, so we'd prefer they don't disappear.
static final int VISIBLE_APP_ADJ = 1;
// This is the process running the current foreground app. We'd really
// rather not kill it!
static final int FOREGROUND_APP_ADJ = 0;
// This is a process that the system or a persistent process has bound to,
// and indicated it is important.
static final int PERSISTENT_SERVICE_ADJ = -11;
// This is a system persistent process, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
static final int PERSISTENT_PROC_ADJ = -12;
// The system process runs at the default adjustment.
static final int SYSTEM_ADJ = -16;
// Special code for native processes that are not being managed by the system (so
// don't have an oom adj assigned by the system).
static final int NATIVE_ADJ = -17;
}
相較於Importance等級而言adj值可以賦予我們更多的參考價值,從上述adj值的定義中我們可以看到,值越小優先順序越高,比如native程序的adj值為-17,對於這個adj值的程序來說,系統根本不會動它一分一毫,實質上當程序的adj值去到2時系統就很少會因為其它原因而去殺死它,這些在研究程序保活中都非常重要。