Android 开机Process xxx (pid xxxx) has died问题分析,金九银十正确打开方式

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 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 = -1; // Currently computed process state: ActivityManager.PROCESS_STATE_*

int repProcState = -1; // Last reported process state

int setProcState = -1; // Last set process state in process tracker

int pssProcState = -1; // 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

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

题外话

我在一线互联网企业工作十余年里,指导过不少同行后辈。帮助很多人得到了学习和成长。

我意识到有很多经验和知识值得分享给大家,也可以通过我们的能力和经验解答大家在IT学习中的很多困惑,所以在工作繁忙的情况下还是坚持各种整理和分享。但苦于知识传播途径有限,很多程序员朋友无法获得正确的资料得到学习提升,故此将并将重要的Android进阶资料包括自定义view、性能优化、MVC与MVP与MVVM三大框架的区别、NDK技术、阿里面试题精编汇总、常见源码分析等学习资料。

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展~

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

【Android思维脑图(技能树)】

知识不体系?这里还有整理出来的Android进阶学习的思维脑图,给大家参考一个方向。

[外链图片转存中…(img-u5sowojd-1712354501450)]

希望我能够用我的力量帮助更多迷茫、困惑的朋友们,帮助大家在IT道路上学习和发展~

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

  • 12
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值