【问题标题】:What is Spurious Death in Android?什么是 Android 中的虚假死亡?
【发布时间】:2015-04-12 14:01:10
【问题描述】:

我知道这听起来是个懒惰的问题。但我真的不知道这种情况是如何发生的,我在 Google 上也找不到太多关于它的信息。

背景:

这是一个带有 IPC 的应用程序:我有一个服务在单独的进程中运行。有时,服务被杀死..但它并没有真正“正式死亡”,而是我从ActivityManager 中得到了一个名为“Spurious death”的术语。发生这种情况时,服务的行为就像僵尸一样。它是有生命的,但它并没有真正发挥作用。

04-12 10:03:37.935 728 830 I ActivityManager:强制完成 活动 ActivityRecord{11eee41f u0 com.android.staging/com.android.activities.MainActivity t8210} 04-12 10:03:37.937 728 830 I ActivityManager:强制停止服务 ServiceRecord{291a4c9b u0 com.android.staging/com.android.services.CallService} 04-12 10:03:37.969 728 2563 W ActivityManager: ProcessRecord{27ecf545 11057:com.android.staging/u0a268} 的虚假死亡,curProc 对于 11057:空

【问题讨论】:

  • 我认为这与内核和内存不足有关...

标签: android


【解决方案1】:

可以在此处找到违规行: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/com/android/server/am/ActivityManagerService.java/#4858 (不同版本的Android L不同的线路)

我假设您使用的是某种形式的 Android L,因为直到那时才添加特定的错误消息。

如果您在进程中运行 ContentProvider,ActivityManagerService 中的这两个 cmets 可能会有所帮助:

9303                     // NOTE: there is still a race here where a signal could be
9304                     // pending on the process even though we managed to update its
9305                     // adj level.  Not sure what to do about this, but at least
9306                     // the race is now smaller.
9307                     if (!success) {
9308                         // Uh oh...  it looks like the provider's process
9309                         // has been killed on us.  We need to wait for a new
9310                         // process to be started, and make sure its death
9311                         // doesn't kill our process.

然后……

9317                         appDiedLocked(cpr.proc);

appDiedLocked 也可以从其他一些源文件中调用:ActiveServices.java 和 ActivityStackSupervisor.java,一个依赖于抛出的 DeadObjectException,另一个依赖于 RemoteException。

appDiedLocked 看起来像这样

4853     final void appDiedLocked(ProcessRecord app, int pid, IApplicationThread thread) {
4854         // First check if this ProcessRecord is actually active for the pid.
4855         synchronized (mPidsSelfLocked) {
4856             ProcessRecord curProc = mPidsSelfLocked.get(pid);
4857             if (curProc != app) {
4858                 Slog.w(TAG, "Spurious death for " + app + ", curProc for " + pid + ": " + curProc);
4859                 return;
4860             }
4861         }

由于某种原因,curProc 与应用程序 ProcessRecord 不同,并且 appDiedLocked 方法被缩短了。在你的情况下 curProc 是空的,再次出于某种原因。

长话短说:您的进程死亡或被杀死,并且某些状态或条件阻止 appDiedLocked 继续运行 killProcess 命令。您需要进行更多调查/记录以找出发生这种情况的原因。

如果你有一个服务想要保持活动状态,除非你已经在做,否则我建议你给它附加一个状态栏通知,这样它被杀死的可能性就会降低。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多