系统中有一个监听BOOT_COMPLETED广播的自启应用,概率性出现启动后被kill掉的现象。Log如下:

- ::40.453   I ActivityManager: Process com.test.xxx (pid ) has died
- ::40.453 D ActivityManager: SVC-handleAppDiedLocked: app = ProcessRecord{19911aa7 :com.test.xxx/u0a41}, app.pid =
- ::40.453 D ActivityManager: SVC-mBroadcastQueues: com.android.server.am.BroadcastQueue@260b97c9
- ::40.453 D ActivityManager: SVC-mBroadcastQueues: com.android.server.am.BroadcastQueue@29a50ece

Log出处:

frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

    final void appDiedLocked(ProcessRecord app, int pid, IApplicationThread thread) {
// First check if this ProcessRecord is actually active for the pid.
synchronized (mPidsSelfLocked) {
ProcessRecord curProc = mPidsSelfLocked.get(pid);
if (curProc != app) {
Slog.w(TAG, "Spurious death for " + app + ", curProc for " + pid + ": " + curProc);
return;
}
} BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
synchronized (stats) {
stats.noteProcessDiedLocked(app.info.uid, pid);
} if (!app.killed) {
Process.killProcessQuiet(pid);
Process.killProcessGroup(app.uid, pid);
app.killed = true;
} // Clean up already done if the process has been re-started.
if (app.pid == pid && app.thread != null &&
app.thread.asBinder() == thread.asBinder()) {
boolean doLowMem = app.instrumentationClass == null;
boolean doOomAdj = doLowMem;
if (!app.killedByAm) {
Slog.i(TAG, "Process " + app.processName + " (pid " + pid
+ ") has died");
mAllowLowerMemLevel = true;
} else {
// Note that we always want to do oom adj to update our state with the
// new number of procs.
mAllowLowerMemLevel = false;
doLowMem = false;
}
EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
if (DEBUG_CLEANUP) Slog.v(
TAG, "Dying app: " + app + ", pid: " + pid
+ ", thread: " + thread.asBinder());
handleAppDiedLocked(app, false, true); if (doOomAdj) {
updateOomAdjLocked();
}
if (doLowMem) {
doLowMemReportIfNeededLocked(app);
}
} else if (app.pid != pid) {
// A new process has already been started.
Slog.i(TAG, "Process " + app.processName + " (pid " + pid
+ ") has died and restarted (pid " + app.pid + ").");
EventLog.writeEvent(EventLogTags.AM_PROC_DIED, app.userId, app.pid, app.processName);
} else if (DEBUG_PROCESSES) {
Slog.d(TAG, "Received spurious death notification for thread "
+ thread.asBinder());
}
}
 

可以看到app.killedByAm = false,也就是说不是ActivityManager主动kill该应用,而是LowMemory的原因(for RAM)。

ProcessRecord里属性:

    private final BatteryStatsImpl mBatteryStats; // where to collect runtime statistics
final ApplicationInfo info; // all about the first app in the process
final boolean isolated; // true if this is a special isolated process
final int uid; // uid of process; may be different from 'info' if isolated
final int userId; // user of process.
final String processName; // name of the process
// List of packages running in the process
final ArrayMap<String, ProcessStats.ProcessStateHolder> pkgList
= new ArrayMap<String, ProcessStats.ProcessStateHolder>();
ArraySet<String> pkgDeps; // additional packages we have a dependency on
IApplicationThread thread; // the actual proc... may be null only if
// 'persistent' is true (in which case we
// are in the process of launching the app)
ProcessStats.ProcessState baseProcessTracker;
BatteryStatsImpl.Uid.Proc curProcBatteryStats;
int pid; // The process of this application; 0 if none
int[] gids; // The gids this process was launched with
String requiredAbi; // The ABI this process was launched with
String instructionSet; // The instruction set this process was launched with
boolean starting; // True if the process is being started
long lastActivityTime; // For managing the LRU list
long lastPssTime; // Last time we retrieved PSS data
long nextPssTime; // Next time we want to request PSS data
long lastStateTime; // Last time setProcState changed
long initialIdlePss; // Initial memory pss of process for idle maintenance.
long lastPss; // Last computed memory pss.
long lastCachedPss; // Last computed pss when in cached state.
int maxAdj; // Maximum OOM adjustment for this process
int curRawAdj; // Current OOM unlimited adjustment for this process
int setRawAdj; // Last set OOM unlimited adjustment for this process
int curAdj; // Current OOM adjustment for this process
int setAdj; // Last set OOM adjustment for this process
int curSchedGroup; // Currently desired scheduling class
int setSchedGroup; // Last set to background scheduling class
int trimMemoryLevel; // Last selected memory trimming level
int curProcState = -; // Currently computed process state: ActivityManager.PROCESS_STATE_*
int repProcState = -; // Last reported process state
int setProcState = -; // Last set process state in process tracker
int pssProcState = -; // The proc state we are currently requesting pss for
boolean serviceb; // Process currently is on the service B list
boolean serviceHighRam; // We are forcing to service B list due to its RAM use
boolean setIsForeground; // Running foreground UI when last set?
boolean notCachedSinceIdle; // Has this process not been in a cached state since last idle?
boolean hasClientActivities; // Are there any client services with activities?
boolean hasStartedServices; // Are there any started services running in this process?
boolean foregroundServices; // Running any services that are foreground?
boolean foregroundActivities; // Running any activities that are foreground?
boolean repForegroundActivities; // Last reported foreground activities.
boolean systemNoUi; // This is a system process, but not currently showing UI.
boolean hasShownUi; // Has UI been shown in this process since it was started?
boolean pendingUiClean; // Want to clean up resources from showing UI?
boolean hasAboveClient; // Bound using BIND_ABOVE_CLIENT, so want to be lower
boolean treatLikeActivity; // Bound using BIND_TREAT_LIKE_ACTIVITY
boolean bad; // True if disabled in the bad process list
boolean killedByAm; // True when proc has been killed by activity manager, not for RAM
boolean killed; // True once we know the process has been killed
boolean procStateChanged; // Keep track of whether we changed 'setAdj'.
String waitingToKill; // Process is waiting to be killed when in the bg, and reason
IBinder forcingToForeground;// Token that is forcing this process to be foreground
int adjSeq; // Sequence id for identifying oom_adj assignment cycles
int lruSeq; // Sequence id for identifying LRU update cycles
CompatibilityInfo compat; // last used compatibility mode
IBinder.DeathRecipient deathRecipient; // Who is watching for the death.
ComponentName instrumentationClass;// class installed to instrument app
ApplicationInfo instrumentationInfo; // the application being instrumented
String instrumentationProfileFile; // where to save profiling
IInstrumentationWatcher instrumentationWatcher; // who is waiting
IUiAutomationConnection instrumentationUiAutomationConnection; // Connection to use the UI introspection APIs.
Bundle instrumentationArguments;// as given to us
ComponentName instrumentationResultClass;// copy of instrumentationClass
boolean usingWrapper; // Set to true when process was launched with a wrapper attached
BroadcastRecord curReceiver;// receiver currently running in the app
long lastWakeTime; // How long proc held wake lock at last check
long lastCpuTime; // How long proc has run CPU at last check
long curCpuTime; // How long proc has run CPU most recently
long lastRequestedGc; // When we last asked the app to do a gc
long lastLowMemory; // When we last told the app that memory is low
boolean reportLowMemory; // Set to true when waiting to report low mem
boolean empty; // Is this an empty background process?
boolean cached; // Is this a cached process?
String adjType; // Debugging: primary thing impacting oom_adj.
int adjTypeCode; // Debugging: adj code to report to app.
Object adjSource; // Debugging: option dependent object.
int adjSourceProcState; // Debugging: proc state of adjSource's process.
Object adjTarget; // Debugging: target component impacting oom_adj.
Runnable crashHandler; // Optional local handler to be invoked in the process crash.

过滤掉特定应用:

        if (!app.killed) {
Process.killProcessQuiet(pid);
Process.killProcessGroup(app.uid, pid);
app.killed = true;
}

修改为:

        if (!app.killed) {
if(!"com.test.xxx".equals(app.processName)){
Process.killProcessQuiet(pid);
Process.killProcessGroup(app.uid, pid);
}
app.killed = true;
}

原文:http://blog.csdn.net/zhoumushui https://blog.csdn.net/zhoumushui/article/details/52239884

Android 开机Process xxx (pid xxxx) has died问题分析的更多相关文章

  1. Android开机动画启动流程

    android开机动画启动流程   从android的Surface Flinger服务启动分析知道,开机动画是在SurfaceFlinger实例通过调用startBootAnim()启动的. 下面我 ...

  2. Android 开机画面和wallpaper总结

    Android 开机画面和wallpaper总结  1 kernel的开机画面修改 1.图片需求:图片格式:png图片大小:1024x600(具体示lcd分辨率而定). 2.转换图片png图片. 假设 ...

  3. Android Kill Process

    /********************************************************************** * Android Kill Process * 说明: ...

  4. android开机启动流程说明

    android开机启动流程说明 第一步:启动linux 1.Bootloader 2.Kernel 第二步android系统启动:入口为init.rc(system\core\rootdir) 1./ ...

  5. Android 开机动画源码分析

    Android系统在启动SystemServer进程时,通过两个阶段来启动系统所有服务,在第一阶段启动本地服务,如SurfaceFlinger,SensorService等,在第二阶段则启动一系列的J ...

  6. OpenGL—Android 开机动画源码分析一

    .1 Android开机动画实现方式目前实现Android开机动画的方式主要是逐帧动画和OpenGL动画. ?逐帧动画 逐帧动画是一种常见的动画形式(Frame By Frame),其原理是在“连续的 ...

  7. apache错误 Unable to open process" with PID 4!

    今天打开Apache的时候报错: 22:15:30  [Apache] Problem detected! 22:15:30  [Apache] Port 80 in use by "Una ...

  8. 如何让A20,android开机自动启动C程序【转】

    本文转载自:http://blog.csdn.net/u011258134/article/details/50749174 如何让A20,android开机自动启动C程序 2014-12-26 11 ...

  9. Error message: Failed to spawn: unable to access process with pid 413 due to system restrictions; try `sudo sysctl kernel.yama.ptrace_scope=0`, or run Frida as root

    Android 8.0 在frida中使用 -f 参数报错, Error message: Failed to spawn: unable to access process with pid 413 ...

随机推荐

  1. js的字符串charAt()方法

    //字符中的字符从左向右进行索引,由0开始,字符串中的空格也算在内 var string = "charAt find word position"; document.write ...

  2. exports和module.exports区别

    参考:module.exports与exports的区别.关于exports的总结 exports 和 module.exports 的区别 module.exports是真正的模块接口,而expor ...

  3. 以前做的H5推广小游戏(活动及派发奖品形式)

    润百颜 1 微信授权登录,获取用户openid.一个openid一次抽奖机会,该openid用户多次玩游戏抽奖,仍然是相同的优惠码. 2 游戏结束抽奖,100%中奖,获得优惠码.优惠码和openid保 ...

  4. [XML] CoolFormat

    http://files.cnblogs.com/files/wjs16/CoolFormat3.4.rar

  5. iOS使用位置和方向服务(来自苹果apple官方)

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   本文章来自苹果官方文档,特此声明--------禚 Core Location框架为定位用户当前位置和方向(Headin ...

  6. PHP移除json数据最右侧的逗号!

    具体函数是:PHP rtrim() 函数 参考地址: http://www.w3school.com.cn/php/func_string_rtrim.asp 参考: <!DOCTYPE htm ...

  7. 【数组】—冒泡排序&&选择排序---【巷子】

    /* 什么是冒泡排序:从头到尾比较相邻的两个数的大小,如果符合条件则进行比较 [注]:从小到大进行排序 假设有一个数组 var arr = [9,8,7,6,5,4]; 我们想要进行这个数组进行排序那 ...

  8. PL/SQL编程基础(二):变量的声明、赋值、(赋值、连接、关系、逻辑)运算符

    变量的声明.赋值.运算符 1.声明并使用变量 变量可以在声明时赋值,也可以先定义后赋值: 使用%TYPE与%ROWTYPE可以根据已有类型定义变量. PL/SQL是一种强类型的编程语言,所有的变量都必 ...

  9. Oracle性能优化之Oracle里的统计信息

    一.什么是统计信息 oracle数据库里的统计信息是如下的一组数据:他们存储在数据字典里,且从多个维度描述了oracle数据库数据对象的详细信息. oracle数据库里的统计信息主要分为以下6种情况: ...

  10. linux加载硬盘过程

    查看系统可用磁盘大小: [root@i-mbyar7df ~]# df -h Filesystem      Size  Used Avail Use% Mounted on /dev/sda1    ...