Android的进程调度 [英] Android Process Scheduling

查看:216
本文介绍了Android的进程调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得这样我就可以从范围潜在的互操作性问题的可靠性影响创建Android应用程序/服务时,一个更深入的了解。我想弄清楚进程的优先级是如何确定的。如果调度程序将其优先级不同的服务和活动之​​间的优先级的差别。基本上我想要得到它是如何可能的活动或服务是从不同的应用程序饿死一个恶意进程有深刻的理解(甚至是Linux内核中。)

I am trying to get a better understanding so I can scope the reliability impact from potential interoperability issues when creating an android app/service. I would like to figure out how process priority is determined. The differences in priority between services and activities and if the scheduler treats their priority differently. Basically I'm trying to get a strong understanding of how likely it is that an activity or service is starved by a rogue processes from a different application (or even the linux kernel.)

有没有人有任何好的链接,您可以推荐...我的搜索没有打开了很多,但。

Does anyone have any good links you could recommend... My searches haven't turned up much, yet.

谢谢!

编辑:我的问题是关于处理器的时间分片/调度,不会内存资源(内存资源在Android文档中很好的描述。)再次感谢!

My concern is with regard to processor time slicing/scheduling, not memory resources (memory resources are well described within the android documentation.) Thanks again!

推荐答案

下面的列表presents按重要性顺序的不同类型的进程(第一个过程是最重要的,是最后一个被杀):

The following list presents the different types of processes in order of importance (the first process is most important and is killed last):

  1. 在前台进程
  2. 在可视进程
  3. 在服务过程中
  4. 后台进程
  5. 空缺过程

注意: Android的行列工艺的最高水平就可以了,根据目前的过程中活跃的组成部分的重要性。例如,如果一个进程承载服务和可见光活性,该过程被列为一个可见的过程,而不是一个服务进程。

Note: Android ranks a process at the highest level it can, based upon the importance of the components currently active in the process. For example, if a process hosts a service and a visible activity, the process is ranked as a visible process, not a service process.

这是从这里引用进程和线程

编辑:

了解应用程序优先级和过程状态

在这过程中被杀死回收资源的顺序是由托管应用程序的优先级决定。一个应用程序的优先级等于其优先级最高的部分。

The order in which processes are killed to reclaim resources is determined by the priority of the hosted applications. An application’s priority is equal to its highest-priority component.

如果两个应用程序具有相同的优先级,即一直处于较低的优先级的过程最长将首先杀死。进程的优先级也受进程间的依赖关系;如果应用程序对由第二应用程序提供的服务或内容提供者的依赖关系,该辅助应用将具有至少尽可能高的优先,因为它支持的应用

Where two applications have the same priority, the process that has been at a lower priority longest will be killed first. Process priority is also affected by interprocess dependencies; if an application has a dependency on a Service or Content Provider supplied by a second application, the secondary application will have at least as high a priority as the application it supports.

所有的Andr​​oid应用程序将继续运行,并在内存中,直到系统需要的资源用于其他应用程序。

All Android applications will remain running and in memory until the system needs its resources for other applications.

重要的是要正确地构建应用程序,以确保其优先级是适合的工作是在做什么。如果不这样做,你的应用程序可以同时它在一些重要的中间被杀死。 下面详细列举每个图中所示的应用程序状态,说明国家如何通过包括它的应用程序组件确定:

It’s important to structure your application correctly to ensure that its priority is appropriate for the work it’s doing. If you don’t, your application could be killed while it’s in the middle of something important. The following list details each of the application states shown in Figure , explaining how the state is determined by the application components comprising it:

活动进程活动(前景)的过程与目前的组件与用户交互的托管应用程序。这些都是过程Android正在努力保持敏感通过回收资源。通常有极少数的这些过程中,他们将只杀死作为最后的手段。

Active Processes Active (foreground) processes are those hosting applications with components currently interacting with the user. These are the processes Android is trying to keep responsive by reclaiming resources. There are generally very few of these processes, and they will be killed only as a last resort.

活动流程包括:

1.Activities处于活动状态;也就是说,它们是在前台和响应用户事件。您将在本章后面探究更详细的活动状态。

1.Activities in an "active" state; that is, they are in the foreground and responding to user events. You will explore Activity states in greater detail later in this chapter.

2.Activities,服务,或广播接收机当前正在执行的的onReceive事件处理程序。

2.Activities, Services, or Broadcast Receivers that are currently executing an onReceive event handler.

这是正在执行的ONSTART,的onCreate,或的onDestroy事件处理3.Services。

3.Services that are executing an onStart, onCreate, or onDestroy event handler.

可视进程可见,但不活动的过程是那些托管看得见的活动。顾名思义,可见活动是可见的,但它们不是在前台或响应用户事件。这发生在当一个活动仅部分遮蔽(由非全屏幕或透明活动)。通常有极少数明显的流程,他们只会在极端的情况下被杀死,使活动的进程继续下去。

Visible Processes Visible, but inactive processes are those hosting "visible" Activities. As the name suggests, visible Activities are visible, but they aren’t in the foreground or responding to user events. This happens when an Activity is only partially obscured (by a non-full-screen or transparent Activity). There are generally very few visible processes, and they’ll only be killed in extreme circumstances to allow active processes to continue.

入门服务流程已经启动的进程托管服务。服务支持正在进行的处理将继续进行,如果没有一个可视界面。因为服务不直接与用户交互,他们收到一个稍微较低的优先级比可见光活动。他们仍然被认为是前台进程,不会被杀死,除非需要进行活动或可见的进程资源。

Started Service Processes Processes hosting Services that have been started. Services support ongoing processing that should continue without a visible interface. Because Services don’t interact directly with the user, they receive a slightly lower priority than visible Activities. They are still considered to be foreground processes and won’t be killed unless resources are needed for active or visible processes.

后台进程进程托管是不可见的,不具有已启动被认为是后台进程的任何服务活动。通常会有大量的后台进程的Andr​​oid将杀死使用最后看到先杀死模板的形式来获得资源,前台进程。

Background Processes Processes hosting Activities that aren’t visible and that don’t have any Services that have been started are considered background processes. There will generally be a large number of background processes that Android will kill using a last-seen-first-killed pat- tern to obtain resources for foreground processes.

空缺进程以提高系统的整体性能,Android的常保留在内存中的应用已达到其寿命结束后。 Android的保持这种高速缓存来提高应用程序的启动时间时,他们再次推出。这些过程都是例行程序tinely杀害必需的。

Empty Processes To improve overall system performance, Android often retains applications in memory after they have reached the end of their lifetimes. Android maintains this cache to improve the start-up time of applications when they’re re-launched. These processes are rou- tinely killed as required.

有关更多信息看这里(我发现这个博客)的内存在Android的管理

For more info look at here(I found on this blog) Memory Management in Android

编辑:

I think Android is basic Linux so, whatever scheduler works for Linux is same in Android. 

Android的调度和Linux调度之间的差异

调度 - 5档 - Android的内核中还包含微小的改变CPU进程调度和时间保持算法。我们不知道这些变化的历史,其影响并不明显基于一个粗略的检查。

Scheduler — 5 files — The Android kernel also contains slight changes to the CPU process scheduler and time-keeping algorithms. We don’t know the history of these changes, and the impact was not evident based on a cursory examination.

处理preemption:

如上所述,Linux操作系统是preemptive。当一个进程进入TASK_RUNNING状态,内核检查是否它的优先级比当前正在执行的进程的优先级更高。如果是,调用调度程序选择一个新的进程运行(presumably刚刚成为可运行的程序)。此外,当一个过程的时间片达到零时,它是preempted,并且调用调度程序以选择一个新的进程。

As mentioned, the Linux operating system is preemptive. When a process enters the TASK_RUNNING state, the kernel checks whether its priority is higher than the priority of the currently executing process. If it is, the scheduler is invoked to pick a new process to run (presumably the process that just became runnable). Additionally, when a process's timeslice reaches zero, it is preempted, and the scheduler is invoked to select a new process.

在行动调度策略

考虑一个系统有两个可运行的任务:一个文本编辑器和视频连接codeR。文本编辑器是I / O密集​​型的,因为它几乎花费所有的时间来等待用户密钥presses(无论有多快,用户类型,它不是那么快)。尽管如此,当它收到一个关键preSS,用户希望编辑器立即响应。相反,视频连接codeR是处理器密集型。除了从磁盘读取的原始数据流,并写入后所产生的视频,带连接codeR花费所有时间施加视频codec至原始数据。它没有在其上运行的,如果什么时候开始,现在还是在半秒运行时,用户不能告诉任何较强的时间限制。当然,越早完成越好。

Consider a system with two runnable tasks: a text editor and a video encoder. The text editor is I/O-bound because it spends nearly all its time waiting for user key presses (no matter how fast the user types, it is not that fast). Despite this, when it does receive a key press, the user expects the editor to respond immediately. Conversely, the video encoder is processor-bound. Aside from reading the raw data stream from the disk and later writing the resulting video, the encoder spends all its time applying the video codec to the raw data. It does not have any strong time constraints on when it runs—if it started running now or in half a second, the user could not tell. Of course, the sooner it finishes the better.

在此系统中,调度器给出所述文本编辑器更高的优先级,以及较大的时间片比视频烯codeR,因为文本编辑器是交互式的。文本编辑器有大量的时间片可用。此外,由于文本编辑器具有更高的优先级,它能够$ P $需要时pempting视频连接$ C $铬。这保证了文本编辑器,能够立即响应用户按键presses的。这是视频连接codeR的损害,但由于文本编辑器只运行间歇,视频连接codeR可以垄断的剩余时间。这不但优化了应用程序的性能。

In this system, the scheduler gives the text editor a higher priority and larger timeslice than the video encoder, because the text editor is interactive. The text editor has plenty of timeslice available. Furthermore, because the text editor has a higher priority, it is capable of preempting the video encoder when needed. This ensure the text editor is capable of responding to user key presses immediately. This is to the detriment of the video encoder, but because the text editor runs only intermittently, the video encoder can monopolize the remaining time. This optimizes the performance of both applications.

这篇关于Android的进程调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆