我有Android应用程序,有一些绑定到某个进程的服务。
我发现adb shell top -n 1
返回:
PID PR CPU% S #THR VSS RSS PCY UID Name
31647 0 1% S 70 1733640K 98960K bg u0_a132 com.my.app.dev
31727 0 1% S 29 1523892K 62924K fg u0_a132 com.my.app.dev:myService
即使我的应用程序处于后台,为什么top
PCY
告诉 'fg'
a.e。前台?
有人能在这个问题上宣传一下吗?
这是我的Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.my.app.dev"
android:versionName="4.0.1.6700000"
android:versionCode="5033" >
<uses-sdk android:minSdkVersion="10"
android:targetSdkVersion="16" />
<application android:icon="@drawable/icon"
android:label="@string/config_app_name"
android:theme="@style/Theme.NoActionBarAppCompat"
android:name="com.my.app.Mine" >
<!-- we would prefer the launchMode to be standard, but it causes a lot of problems. -->
<activity android:name="com.my.ui.main.MineApp"
android:label="@string/config_app_name"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:theme="@style/Theme.Translucent.NoActionBarAppCompat" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="mine.action.HomeActivity" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxx" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<uses-library android:name="com.google.android.maps" />
<service android:name="com.my.engine.logic.EngineService"
android:process=":myService">
<intent-filter>
<action android:name="com_my_RemoteService" />
<action android:name="com_my_EngineService" />
</intent-filter>
</service>
<receiver
android:name="com.my.engine.analytics.ReferrerReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action
android:name="com.android.vending.INSTALL_REFERRER"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.BootBroadcastReceiver"
android:process=":myService">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.util.MineWatcherReceiver"
android:process=":myServiceWatcher">
<intent-filter>
<action
android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action
android:name="android.intent.action.BATTERY_OKAY" />
<action
android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action
android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.InitServiceReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action android:name="initServiceCheck"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.UpdateCounterReceiver"
android:exported="true" android:process=":myService">
<intent-filter>
<action android:name="updateCustomCounter"/>
</intent-filter>
</receiver>
<receiver
android:name="com.my.engine.logic.PackageChangeReceiver"
android:process=":myService">
<intent-filter>
<action
android:name="android.intent.action.PACKAGE_ADDED"/>
<action
android:name="android.intent.action.PACKAGE_REPLACED"/>
<action
android:name="android.intent.action.PACKAGE_REMOVED"/>
<action
android:name="android.intent.action.PACKAGE_INSTALL"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<!-- for notification try next action -->
<service android:name="com.my.notifications.actions.TryNextNotificationActionService" />
<receiver android:name="com.my.ui.base.EulaReminderReceiver">
<intent-filter>
<action android:name="eulaReminderAction" />
</intent-filter>
</receiver>
<receiver android:name="com.my.ui.base.MineGuiBroadcastReceiver">
<intent-filter>
<action android:name="finishStoppedActivities" />
</intent-filter>
</receiver>
<service android:name="com.my.infra.motion.ActivityRecognitionService"
android:label="ActivityRecognitionService"
android:exported="true"
android:enabled="true"
android:process=":myService">
</service>
</application>
</manifest>
编辑1
我甚至停止了设置的通知,但是前台仍然是process=":myService
编辑2
来自资料来源
if (p == SP_BACKGROUND)
strcpy(proc->policy, "bg");
else if (p == SP_FOREGROUND)
strcpy(proc->policy, "fg");
else
strcpy(proc->policy, "er");
来自其他问题的答案
用于PCY的 PCY --策略--决定Android的内存管理器应该如何对待应用程序 前台进程被认为是前台进程,不应该被终止以释放内存。 BG -背景进程被认为是一个后台进程(不活跃地在前台运行,可能会被终止以释放内存)。
发布于 2015-09-21 19:25:24
详细阐述亚历克斯·P.的回答:
我相信PCY列是指流程分配给的cgroup
。Android定义了两个cgroup
组,SP_FOREGROUND
和SP_BACKGROUND
。SP_BACKGROUND
的实际名称是bg_non_interactive
。这些组分别用top
表示,缩写为fg
和bg
。
您可以在整个框架中找到这些引用,特别是在Process.java
、IPCThreadState.cpp
和android_util_Process.cpp
中的本机代码中,这些代码与Linux/proc
文件系统接口,以管理正在运行的进程的各个方面。根据这些文件中注释的源代码,前台cgroup
中的所有线程似乎都是用CPU的“正常”份额调度的,而后台cgroup
中的线程则是用“缩减”份额调度的。
至于正常和简化的定义,这博客指出,SP_BACKGROUND
线程仅限于5%的CPU使用率。您可以通过查看正在运行的设备上的/dev/cpuctl/bg_non_interactive/cpu.shares
来确认这一点。在我运行AOSP 5.1的Nexus 5上,我得到:
root@hammerhead:/ # cat /dev/cpuctl/bg_non_interactive/cpu.shares
52
root@hammerhead:/ #
在这里,52是指cgroup
中线程所允许的'CPU共享‘的数量,最多为1024个共享。因此,在这种情况下,确实允许bg_non_interactive
线程对组中的所有线程最多使用5%的CPU。
无论如何,很明显前景和背景与安卓的活动生命周期以及前台和后台应用程序的概念没有什么关系。这就是安卓利用Linux的cgroups
工具的方式。
发布于 2015-09-21 18:06:10
PCY
代表scheduling policy
。该列中的fg
意味着进程获得比bg
更高的优先级。这并不意味着进程正在前景中运行。
https://stackoverflow.com/questions/32701187
复制相似问题