WO2018045934A1 - 应用进程的管理方法和终端设备 - Google Patents

应用进程的管理方法和终端设备 Download PDF

Info

Publication number
WO2018045934A1
WO2018045934A1 PCT/CN2017/100444 CN2017100444W WO2018045934A1 WO 2018045934 A1 WO2018045934 A1 WO 2018045934A1 CN 2017100444 W CN2017100444 W CN 2017100444W WO 2018045934 A1 WO2018045934 A1 WO 2018045934A1
Authority
WO
WIPO (PCT)
Prior art keywords
application
foreground
group
current
fork
Prior art date
Application number
PCT/CN2017/100444
Other languages
English (en)
French (fr)
Inventor
陈秋林
赖俊
应云剑
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP17848107.3A priority Critical patent/EP3506093A4/en
Publication of WO2018045934A1 publication Critical patent/WO2018045934A1/zh
Priority to US16/296,503 priority patent/US20190205160A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked
    • G06F9/4818Priority circuits therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5061Partitioning or combining of resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/482Application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Definitions

  • the present application relates to the field of terminal devices, and in particular, to a management method and a terminal device of an application process.
  • terminal devices As the variety of applications on terminal devices increases, the use of terminal devices becomes more and more common. There are many operating systems for terminal devices. Among them, Linux-based Android is the most commonly used operating system for terminal devices.
  • Android is a multi-tasking operating system.
  • the background application process will continue to run. This will cause the background application process to compete with the foreground application process for processor resources. As a result, the foreground application often appears to be stuck.
  • the main idea of the front-end and back-end mechanism based on the cgroup is to divide the foreground application process into the foreground process group (fore group, fg), and allocate more processing resources to the processes in the foreground process group, and divide the background application process as much as possible.
  • the background process group back group, bg
  • a process in a foreground process group can use all of the processor cores and can consume 95% of the processor's usage; processes in the background process group can only use one processor core and can occupy up to 5 of the processor. % usage.
  • the application provides a management method and a terminal device of an application process to alleviate the staging phenomenon of the foreground application.
  • the first aspect provides a management method for an application process, including: starting an application in a terminal device; updating an information of a group of processes in the application when an event of the application switching from the foreground to the background occurs, so that the At least part of the process of the target process of the application is transferred from the foreground process group to the background process group, and the target process is a process that still satisfies the condition of the foreground process group after the application switches to the background.
  • the target process is a process that still meets the conditions of the foreground process group after the application switches to the background. If the existing technology is used, the target process will remain in the foreground process group and preempt the resources with the foreground process.
  • the grouping status of the process in the application is updated, so that at least part of the process in the target process of the application is transferred from the foreground process group to the background process group, which can reduce the process of preempting resources with the foreground process to some extent. The number of them, thus alleviating the system's stuttering phenomenon.
  • the condition still remaining in the foreground process group includes at least one of the following conditions: a fork sub-process of the application process; having a foreground service; having an associated process, and the previous grouping of the current process of the associated process Grouped into foreground process groups.
  • the fork process of the application process may refer to a child process created by the application process through the fork() function.
  • updating the group status of the process in the application may refer to: updating the group of processes in the application by triggering an event that the application switches from the foreground to the background as a trigger event.
  • the state in other words, updates the grouping status of processes in the application in response to an event that the application switches from the foreground to the background.
  • the terminal device continuously updates the packet state of the process through the AMS.
  • the process controlled by the AMS will update the packet state, from the previous packet update to the current packet, of course.
  • the previous and current packets of the process may be the same group or different groups. Therefore, the previous grouping of the associated process may refer to the group to which the associated process belongs before the last update of the grouping state of the associated process by the AMS.
  • the current grouping of the associated process may refer to the group to which the associated process belongs after the last update of the grouping state of the associated process by the AMS.
  • the previous packet of the associated process and the current packet may be the same or different.
  • the target process includes at least one of: a fork subprocess of a process of the application; a process having an associated process, and the association The previous grouping of the current grouping of the process is the foreground process group; and the process that is forced to be set in the foreground.
  • the target process includes a fork subprocess of a process of the application, and the process in the application is updated
  • the grouping status includes: identifying the fork sub-process from a plurality of processes of the application; updating a group status of the fork sub-process, causing a group status of the fork sub-process and a parent process of the fork sub-process The grouping status remains the same.
  • AMS can only control the process created by zygote (zygote is a process used to create a process, which can be called a hatching process), and cannot control the fork process of the application process. If the fork process of the application process is in the foreground process group Then, the fork child process will remain in the foreground process group, and compete with the foreground application process for resources.
  • This scheme updates the group state of the fork child process based on the grouping state of the parent process of the fork child process, so that the fork child process is grouped.
  • the state is consistent with the grouping state of the parent process, thus ensuring that the grouping state of the fork child process can be updated in real time, not always in the foreground process group, and further, the fork child process is consistent with the grouping state of the parent process. It is convenient to share resources between the two.
  • the identifying the fork sub-process from the multiple processes of the application including: from the multiple processes
  • the fork sub-process is searched in the cgroup.procs file, where the process identifier of the fork sub-process is recorded in the cgroup.procs file of the multiple processes.
  • the method before the searching for the fork sub-process in the cgroup.procs file of the multiple processes, the method further The method includes: determining, according to a process identifier of a main process of the application, a user identifier of the application; querying, according to the user identifier of the application, a process identifier of the multiple processes; according to the user identifier of the application, and the The process ID of multiple processes determines the path of the cgroup.procs file of the multiple processes.
  • the updating a group status of a process in the application includes: determining a current to be grouped of the application The process associated with the process; If the current group of the associated process is a foreground process group, the current process is classified into a foreground process group; if the current group of the associated process is a background process group, the current process is classified into Background process group.
  • the packet state of the current process is updated based on the previous packet of the current packet of the associated process, and the specific update mode is to set the previous packet of the associated process as the current packet of the current process, if according to the prior art.
  • the way to update the grouping status of the current process causes the following problem: If an application is switched from the foreground to the background, the current grouping of the processes in the application will be updated, and the result of the update may be the foreground process group, or it may be The background process group, however, since the application was previously in the foreground, the previous grouping of the current grouping of the application's process is the foreground process group, so that if the processing according to the prior art is used, regardless of the current state of the application process Whether the group is updated to the foreground process group or the background process group, and the process associated with the application process is left in the foreground process group.
  • the solution updates the group status of the current process based on the current group of the associated process, so that the current process group is associated with it.
  • the current grouping of processes is consistent and can avoid the above problems It occurs, so that the application switching from the foreground to the background, associated with the application process associated with the process there is a possibility of entering a background process group.
  • the updating a packet state of a process in the application includes: a current to be grouped in the application If the process does not include an activity in a visible state or a suspended state, updating the grouping state of the current process according to whether the current process is forcibly set in the foreground; if the current process is forcibly set in the foreground, The current process belongs to the foreground process group; if the current process is not forcibly set in the foreground, the current process is classified into the background process group.
  • the current process does not include an activity in a visible state or a suspended state, it is required to update the grouping state of the current process according to whether the current process has a foreground service. If the current process has a foreground service, the current process is returned. Enter the foreground process group and exit the current process group update process. If the current process does not have the foreground service, the current process will be classified into the background process group, and continue to update the current process's group status according to whether the current process is forced to be set in the foreground. The update method will cause the process with the foreground service to remain in the foreground process group, and the foreground process will preempt the resources, causing the system to be stuck.
  • This solution does not need to update the current process group state according to whether the current process has the foreground service, so that the current process It will not stay in the foreground process group due to the presence of the front-end service, which will alleviate the system's stuck phenomenon to some extent.
  • a second aspect provides a management method for an application process, including: identifying a fork sub-process of the application process from multiple processes of an application; updating a packet state of the fork sub-process, and grouping the fork sub-process The state is consistent with the grouping state of the parent process of the fork child process.
  • the AMS cannot control the fork process of the application process. If the fork process of the application process is in the foreground process group, the fork child process will remain in the foreground process group and compete for resources with the foreground application process.
  • the scheme updates the grouping state of the fork child process based on the grouping state of the parent process of the fork child process, so that the grouping state of the fork child process is consistent with the grouping state of the parent process, thereby ensuring that the grouping state of the fork child process can be updated in real time. It will not always stay in the foreground process group. Further, the fork child process will be consistent with the grouping state of its parent process, which can facilitate resource sharing between the two.
  • the identifying the fork sub-process from the plurality of processes of the application includes: searching for a location from the cgroup.procs file of the multiple processes The fork child process, wherein the process identifier of the fork child process is recorded in a cgroup.procs file of the multiple processes.
  • the method before the searching for the fork sub-process from the cgroup.procs file of the multiple processes, the method further includes: according to the application The process ID of the main process, Determining the user identifier of the application; querying the process identifier of the multiple processes according to the user identifier of the application; determining the multiple processes according to the user identifier of the application and the process identifier of the multiple processes The path to the cgroup.procs file.
  • a third aspect provides a management method of an application process, including: starting an application in a terminal device; determining an association process of a current process to be grouped by the application when an event of the application switching from the foreground to the background occurs; If the current group of the associated process is a foreground process group, the current process is classified into a foreground process group; if the current group of the associated process is a background process group, the current process is classified into Background process group.
  • the packet state of the current process is updated based on the previous packet of the current packet of the associated process, and the specific update mode is to set the previous packet of the associated process as the current packet of the current process, if according to the prior art.
  • the way to update the grouping status of the current process causes the following problem: If an application is switched from the foreground to the background, the current grouping of the processes in the application will be updated, and the result of the update may be the foreground process group, or it may be The background process group, however, since the application was previously in the foreground, the previous grouping of the current grouping of the application's process is the foreground process group, so that if the processing according to the prior art is used, regardless of the current state of the application process Whether the grouping is a foreground process group or a background process group, and the processes associated with the application process are all left in the foreground process group.
  • the solution updates the grouping status of the current process based on the current grouping of the associated process, so that the current process is grouped with the current process.
  • the current grouping of the associated processes is consistent and can avoid the above problems It occurs, so that the possibility of entering even the background process group from the foreground to the background application switching, associated with the application process associated with the process are also present.
  • the fourth aspect provides a management method of an application process, including: starting an application in a terminal device; when an event that the application switches from the foreground to the background occurs, the current process to be grouped in the application does not include being visible.
  • the grouping state of the current process is updated according to whether the current process is forcibly set in the foreground; if the current process is forcibly set in the foreground, the current process is classified into the foreground a process group; if the current process is not forcibly set in the foreground, the current process is classified into a background process group.
  • the current process does not include an activity in a visible state or a suspended state, it is required to update the grouping state of the current process according to whether the current process has a foreground service. If the current process has a foreground service, the current process is returned. Enter the foreground process group and exit the current process group update process. If the current process does not have the foreground service, the current process will be classified into the background process group, and continue to update the current process's group status according to whether the current process is forced to be set in the foreground. The update method will cause the process with the foreground service to remain in the foreground process group, and the foreground process will preempt the resources, causing the system to be stuck.
  • This solution does not need to update the current process group state according to whether the current process has the foreground service, so that the current process It will not stay in the foreground process group due to the presence of the front-end service, which will alleviate the system's stuck phenomenon to some extent.
  • a terminal device comprising means for performing the method described in any one of the first to fourth aspects.
  • a terminal device includes a memory for storing a program, a processor for executing a program, and when the program is executed, the processor is specifically configured to execute the first The method described in any one of the fourth aspect.
  • a seventh aspect a computer readable medium for storing program code, the program code comprising instructions for performing the method of any of the first to fourth aspects .
  • Figure 1 is a flow chart of the existing AMS management process.
  • FIG. 2 is a schematic diagram of a terminal device according to an embodiment of the present application.
  • FIG. 3 is a schematic diagram of a computer system provided by an embodiment of the present application.
  • FIG. 4 is a schematic flowchart of a method for managing an application process according to an embodiment of the present application.
  • FIG. 5 is a detailed flow chart of step 420 of FIG.
  • FIG. 6 is a schematic flowchart of a method for managing an application process according to an embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a terminal device according to an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of a terminal device according to another embodiment of the present application.
  • the management method of the application process provided by the embodiment of the present application is mainly applied to a terminal device, which may also be called a user equipment (User Equipment, UE), a mobile station (Mobile Station, MS), a mobile terminal (Mobile Terminal), and the like.
  • the terminal may have the capability of communicating with one or more core networks via a Radio Access Network (RAN), for example, the terminal may be a mobile phone (or “cellular” phone), Or a computer with a mobile nature, for example, the terminal can also be a portable, pocket-sized, handheld, computer-integrated or in-vehicle mobile device.
  • RAN Radio Access Network
  • the management method of the application process provided by the embodiment of the present application can be applied to other types of computer systems, in addition to the terminal device.
  • FIG. 1 is a schematic structural diagram of a terminal device applied to an embodiment of the present application.
  • the terminal device 100 includes a memory 180, a processor 150, and a display device 140.
  • the memory 180 stores a computer program including an operating system program 182, an application 181, and the like.
  • the processor 150 is configured to read a computer program in the memory 180 and then execute a computer program defined method, for example, the processor 150 reads the operating system program 182 to run an operating system on the terminal device 100 and implement various functions of the operating system. Or reading one or more applications 181 to run the application on the terminal device.
  • Processor 150 may include one or more processors.
  • processor 150 may include one or more central processors or include a central processing unit and a graphics processor.
  • the processor 150 includes a plurality of processors, the plurality of processors may be integrated on the same chip, or may each be a separate chip.
  • a processor can include one or more processing cores.
  • the memory 180 also stores other data 183 in addition to the computer program.
  • the other data 183 may include data generated by the operating system 182 or the application 181 after being run, the data including system data (such as operating system configuration parameters) and User data.
  • Memory 180 generally includes memory and external memory.
  • the memory can be random access memory (RAM), read only memory (ROM), and cache (CACHE).
  • the external storage can be a hard disk, a CD, a USB disk, a floppy disk, or a tape drive.
  • Computer programs are typically stored on external storage, and the processor loads the computer program from external memory into memory before processing.
  • the operating system program 182 includes a computer program that can implement the management method of the application process provided by the embodiment of the present application, so that after the processor 150 reads the operating system program 182 and runs the operating system, the operating system can have the operating system. Apply the management method function of the application process provided by the embodiment.
  • the terminal device 100 may further include an input device 130 for receiving input digital information, character information or contact touch operation/contactless gesture, and generating a message related to user setting and function control of the terminal device 100. Number input, etc.
  • the input device 130 may include a touch panel 131.
  • the touch panel 131 also referred to as a touch screen, can collect touch operations on or near the user (such as the user's operation on the touch panel 131 or on the touch panel 131 using any suitable object or accessory such as a finger, a stylus, or the like. ), and drive the corresponding connection device according to a preset program.
  • the touch panel 131 may include two parts: a touch detection device and a touch controller.
  • the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information.
  • the processor 150 is provided and can receive commands from the processor 150 and execute them.
  • the touch panel 131 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves.
  • the input device 130 may further include other input devices 132.
  • the other input devices 132 may include, but are not limited to, a physical keyboard, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like. One or more of them.
  • the terminal device 100 may further include a display device 140, including a display panel 141, for displaying information input by the user or information provided to the user, and various menu interfaces of the terminal device 100, etc., in the embodiment of the present application. It is mainly used for the application process of the foreground or the desktop of the terminal device.
  • the display device 140 may include a display panel 141.
  • the display panel 141 may be configured in the form of an LCD (Liquid Crystal Display) or an OLED (Organic Light-Emitting Diode).
  • the touch panel 131 can cover the display panel 141 to form a touch display screen.
  • the terminal device 100 may further include a power source 190 for supplying power to other modules and a camera 160 for taking a photo or video.
  • the terminal device 100 may also include one or more sensors 120, such as acceleration sensors, light sensors, and the like.
  • the terminal device 100 may further include a radio frequency (RF) circuit 110 for performing network communication with the wireless network device, and may further include a WiFi module 170 for performing WiFi communication with other devices.
  • RF radio frequency
  • the management method of the application process provided by the embodiment of the present application can be implemented in the operating system 182 shown in FIG. 1.
  • the operating system can be an Android operating system.
  • the implementation of the method provided by the embodiment of the present application is described in the following with reference to FIG.
  • FIG. 2 is a schematic structural diagram of a computer system 200 according to an embodiment of the present application.
  • the computer system can be a terminal device, including an application layer 210 and an operating system layer 250, and the operating system can be an Android operating system.
  • the operating system layer 250 is further divided into a framework layer 220, a core library layer 230, and a driver layer 240.
  • the operating system layer 250 in FIG. 2 can be considered as a specific implementation of the operating system 182 in FIG. 1.
  • the application layer 210 in FIG. 2 can be considered as a specific implementation of the application 181 in FIG.
  • the drive layer 240 includes a CPU driver 241, a GPU driver 242, a display controller driver 243, and the like.
  • the core library layer 230 is a core part of the operating system, including an input/output service 231, a core service 232, a graphics device interface 234, and a graphics engine (Graphics Engine) 233 that implements CPU or GPU graphics processing.
  • the graphics engine 233 may include a 2D engine, a 3D engine, a composition, a frame buffer, an EGL (Embedded-System Graphics Library), etc., wherein the EGL is a rendering API and an underlying native platform window system.
  • Interface, API refers to the application programming interface (Application Programming Interface).
  • the framework layer 220 may include a Graphic Service 224, a System Service 221, a Web Service 222, and a Customer Service 223, etc.
  • the graphics service 224 may include, for example, a widget (Widget). ), canvas (Canvas) and views (Views).
  • the application layer 210 may include a gallery 211, a media player (Media Player) 212, and a browser (Browser) 213. Wait.
  • computer system 200 also includes a hardware layer 250.
  • the hardware layer of the computer system 200 may include a Central Processing Unit (CPU) 251 and a Graphic Processing Unit (GPU) 252 (corresponding to a specific implementation of the processor 150 in FIG. 1).
  • a memory 253 (corresponding to the memory 180 in FIG. 1), including memory and external memory, may also include an input device 254 (corresponding to the input device 132 in FIG. 1) and a display device 255 (corresponding to the display in FIG. 1).
  • Apparatus 140 such as a Liquid Crystal Display (LCD), Holographic, Projector, etc., may also include one or more sensors 256 (equivalent to sensor 120 in FIG. 1).
  • the hardware layer 250 may also include the power source, camera, RF circuit, and WiFi module shown in FIG. 1, and may also include other hardware modules not shown in FIG. 1, such as a memory controller and display control. And so on.
  • the management method of the application process provided by the embodiment of the present application can be implemented in the operating system execution layer 250 in FIG. 2.
  • the prior art introduces a front-end and back-end mechanism based on cgroup in order to alleviate the staging phenomenon of the foreground application.
  • the front-end and back-end mechanism is introduced, when there are many applications running at the same time, the foreground application will still be stuck.
  • this kind of stuck phenomenon is caused by some processes in the application still being satisfied after the application switches to the background.
  • the process of the application that is still in the foreground process group after the application is switched to the background.
  • the embodiment of the present application does not specifically limit the type of the target process.
  • the following is an example.
  • the target process may include processes that are not governed by an Activity Manager Service (AMS), such as a fork process of an application process.
  • AMS Activity Manager Service
  • AMS is an important part of the operating system, mainly providing the following main functions: unified scheduling of activities of each application (Activity); memory management; and process management.
  • the AMS is part of the system service 221 in Figure 2.
  • the cgroup-based front-end grouping mechanism is performed under the control of the AMS, that is, the AMS is used to update the packet state of the process.
  • AMS can only control the process created by zygote (zygote is the process used to create the process, which can be called the incubation process), the fork process of the application process (that is, the child process created by the application process in the fork mode, or the application itself passes
  • the child process generated by the fork() call is not controlled by the AMS. This will cause the group state of the fork process of the application process to be unupdated, which will cause some fork child processes to remain in the foreground process group.
  • the target process may include processes that are governed by the AMS, such as processes with foreground services, processes that are forced to be set in the foreground, and the like.
  • the AMS when an application background switching event occurs, the AMS updates the group status of the AMS-controlled process based on certain conditions and logic. In other words, when the application background switch event occurs, the process that meets certain conditions will enter the background process group as the application switches to the background, but the process that meets certain conditions will remain in the foreground process group, as mentioned above.
  • a process with front-end services For ease of understanding, the existing AMS management process is introduced in conjunction with FIG.
  • FIG. 3 is a flow chart of the existing AMS control flow process, and the AMS updates the group status of the processes controlled by the AMS based on the control flow shown in FIG. 3.
  • an application launch event an application switching from a background to a foreground event, a process receiving a broadcast event, and the like.
  • step 313 is performed, and the process is classified into the foreground process group and exited. If the current process is not the foreground process or the process that is receiving the broadcast, step 303 is performed.
  • the process controlled by the AMS generally updates the process group according to the process shown in FIG. 3, and the current process in step 302 refers to the AMS controlled by the AMS in the terminal device. Process, and the process is updating the grouping status through the flow of Figure 3.
  • the Android system defines four major components, namely activity, service, content provider, and broadcast receiver.
  • the activity is usually a separate window, and the activities communicate through the Intent. Further, activities generally include four basic states: active or running, paused, stopped, and killed.
  • step 304 if the current process includes the activity of the visible state or the suspended state, step 313 is performed, which is classified into the foreground process group and exits (ie, the packet state update process of the current process is ended); if the current process does not contain the visible state or To pause the activity, go to step 305.
  • a service is generally a program with a long life cycle and no user interface.
  • the program usually runs in the background.
  • the service in the background has a low priority and there is a possibility of being killed. Therefore, some applications will let the service run in the foreground through the startForeground function.
  • step 313 assign it to the foreground process group and exit; if the current process does not have the foreground service, go to step 306.
  • step 307 if the process has a Heavy Weight attribute, step 310 is performed to classify it into the background process group; if the process does not have the Heavy Weight attribute, step 308 is performed.
  • step 310 If the current process is a desktop process, go to step 310 and assign it to the background process group. If the current process is not a desktop process, go to step 309.
  • step 310 is performed to be classified into the background process group; if the current process is not the process of the previous application in the foreground, step 311 is performed.
  • the application in the foreground is constantly changing. For example, when the user first starts the application A, the application A is in the foreground, and then the user starts the application B. At this time, the application B becomes the foreground application. When the application A becomes the previous application in the foreground; next, if the user presses the HOME button to cause the application B to switch from the foreground to the background, the application B becomes the previous application in the foreground.
  • the current process is classified into a background process group.
  • the current process has a running service or a content provider (by the content provider, the specified data set of one application can be provided to other applications, that is, the data between the applications can be implemented by the content provider. Share) to determine if the current process has an associated process.
  • step 312 If the current process has a running service or content provider, indicating that the current process has an associated process, go to step 312; otherwise, exit directly.
  • the current process is classified into the foreground process group. If the associated process is grouped as the background process group, the current process is classified into the background process group, that is, the current process.
  • the grouping is consistent with the previous grouping of the associated process.
  • the terminal device continuously updates the packet state of the process through the AMS.
  • the process controlled by the AMS will update the packet state, from the previous packet update to the current packet, of course.
  • the previous and current packets of the process may be the same group or different groups. Therefore, the previous grouping of the associated process may refer to the group to which the associated process belongs before the last update of the grouping state of the associated process by the AMS.
  • the current grouping of the associated process may refer to the group to which the associated process belongs after the last update of the grouping state of the associated process by the AMS.
  • the previous packet of the associated process and the current packet may be the same or different.
  • the current process is classified into the foreground process group.
  • the target process can include this type of target process.
  • the target process may include at least one of the following processes: a process having an associated process, and the previous grouping of the current grouping of the associated process is a foreground process group; a process having a foreground service; and a process forced to be set in the foreground.
  • FIG. 4 is a schematic flowchart of a method for managing an application process according to an embodiment of the present application.
  • the method of FIG. 4 may be performed by a terminal device, and may be performed by an operating system of the terminal device, such as the operating system layer 250 in FIG.
  • the method of Figure 4 includes:
  • the above application may refer to an application currently running in the terminal device.
  • it may be a shopping application, a music application or a social network application, etc. currently opened by the terminal device.
  • the target process is a process that still meets the conditions of the foreground process group after the application switches to the background. If the existing technology is used, the target process will remain in the foreground process group, and the foreground process preempts resources.
  • the embodiment updates the grouping status of the process in the application when the application switches from the foreground to the background, so that at least part of the processes in the target process of the application are transferred from the foreground process group to the background process group, which can alleviate the target process to some extent. Preempting resources with the foreground process.
  • the target process may include a process that is not controlled by the AMS, such as a fork child process of the applied process; or the target process may include a process that is controlled by the AMS, such as a process with an associated process in the application, and the associated process
  • the previous grouping of the current grouping is the foreground process group, the process with the foreground service in the application, or the process in the application that is forced to be set in the foreground.
  • the execution manner of step 420 corresponding to different types of target processes may be different, and is described in detail below in conjunction with specific embodiments.
  • the target process includes a fork sub-process of the process of the application
  • step 420 may include: identifying a fork sub-process of the application process from among the multiple processes of the application; setting the process group to which the fork sub-process belongs As a background process group.
  • the application includes Process 1, Process 2, Process 3, and Process 4, wherein Process 2 and Process 3 are identified fork child processes, and at this time, Process 1 and Process 4 can update the process group to which they belong based on the AMS.
  • the process group to which process 2 and process 3 belong can be directly set as the background process group.
  • the embodiment of the present application directly transfers the identified fork sub-process to the background process group, which is simple in operation and easy to implement.
  • the target process includes a fork sub-process (a fork process) of the process of the application, and step 420 may include:
  • the embodiment of the present application updates the grouping state of the fork child process based on the grouping state of the parent process of the fork child process, so that the grouping state of the fork child process is consistent with the grouping state of the parent process, thereby ensuring that the grouping state of the fork child process can be obtained in real time. Update, further, the fork subprocess is consistent with the grouping state of its parent process, which can facilitate resource sharing between the two.
  • the step 424 may include: updating, by the AMS, a packet status of the remaining processes other than the fork sub-process in the application; updating the group status of the fork sub-process according to the group status of the remaining process, and making the group status of the fork sub-process It is consistent with the grouping status of the parent process of the fork child process.
  • the embodiment does not limit the grouping of the remaining processes.
  • the group status of the fork sub-process is updated.
  • the group status of the remaining processes can be updated, and the group status of the fork sub-process can be updated, or the two can be cross-processed.
  • the application includes Process 1, Process 2, Process 3, and Process 4, where Process 3 and Process 4 are identified fork child processes, Process 1 is the parent process of Process 3, and Process 2 is the parent process of Process 4.
  • Process 1 and Process 2 are the remaining processes except the fork child process.
  • a feasible update method first update the group status of process 1 and process 2 based on AMS, and then update the group status of process 3 and process 4 to be consistent with the group status of process 1 and process 2, respectively;
  • a feasible update method first update the packet state of process 1 based on AMS, then update the packet state of process 3 to be consistent with the packet state of process 1, and then update the packet state of process 2 based on AMS, and then update process 4
  • the grouping status is consistent with the grouping status of Process 2.
  • the parent process of a fork child process (hereinafter referred to as the first fork child process) is also a fork child process (hereinafter referred to as a second fork child process)
  • the parent process of the second fork child process may first update the grouping state of the parent process of the second fork child process based on the AMS, and then update the grouping state of the second fork child process, so that the grouping state of the second fork child process and its parent process
  • the packet state is consistent, and then the packet state of the first fork sub-process is updated, so that the packet state of the first fork sub-process is consistent with the packet state of the second fork sub-process.
  • the setProcessGroup function can be called to adjust the process group of the fork child process, and the process group of the fork child process and the process of the parent process. The group is consistent.
  • the implementation of the step 422 may be multiple.
  • the fork sub-process of the application process may be pre-recorded.
  • the record table of the fork sub-process may be pre-established, and one for each fork is applied.
  • the child process records the process ID of the child process in the record table. When it needs to be used, the record table can be searched to identify the fork child process.
  • step 422 may include: searching for a fork child process from a cgroup.procs file of multiple processes, where a process identifier of the fork child process is recorded in a cgroup.procs file of multiple processes. .
  • the cgroup.procs file is a file type supported by the cgroup mechanism, and one process corresponds to a cgroup.procs file, the process identifier of the process is recorded in the cgroup.procs file, and the process identifier of the fork child process of the process is recorded.
  • the cgroup.procs file corresponding to a process is usually located in the following file path: /acct/uid_xxx/pid_xxx/cgroup.procs, where uid_xxx indicates the application user ID and pid_xxx indicates the process ID of the process.
  • process 1's cgroup.procs file records the process ID of process 1 and the process ID of process 3, and process 3 is the fork child process of process 1;
  • the cgroup.procs file of 2 records the process ID of process 2, and the process 2 has no fork subprocess;
  • the cgroup.procs file of process 3 records the process ID of process 3 and the process ID of process 4, and process 4 is process 3
  • the cgroup.procs file of process 4 records the ID of process 4, and process 4 has no fork subprocess.
  • the fork subprocess queried from the cgroup.procs file of the above four processes is process 3 and process 4.
  • step 422 can be performed by first querying the number of processes recorded in the cgroup.procs file of a certain process, if The number of processes is greater than 1, indicating that the process has a fork child process; if the number of processes is 1, it indicates that the process does not have a fork child process, and continues to query the cgroup.procs file of the next process until all the cgroup.procs files of the process are queried. .
  • the path of the cgroup.procs file of multiple processes of the application may be determined first, and then the fork child process of the application process may be searched for.
  • the path of the cgroup.procs file of the multiple processes of the application may be obtained by: determining the user identifier of the application according to the process identifier of the main process of the application; and querying the process identifier of the multiple processes according to the user identifier of the application; Determine the path of the cgroup.procs file of multiple processes based on the user ID of the application and the process ID of multiple processes.
  • each application has a user identification (uid) for uniquely identifying the application.
  • you can determine the user ID of the application by querying the configuration information of the application.
  • a process identifier record table of the application process is created.
  • the process identifier of the process is recorded in the record table for each process generated by the application.
  • the process identifier of the application process can be obtained through the record table.
  • a count value and a count value threshold may be preset, the count value indicating the number of queries of the fork process of the application process, when the application switches from the foreground to When the background event occurs, if the count value is less than the count threshold, the fork process of the application process is queried from the cgroup.procs file of the application process; if the count value is greater than or equal to the count threshold, the applied fork process is considered to remain substantially unchanged. , the last query result can be reused to speed up the recognition of the fork child process.
  • the fork process of the application process can be recorded by means of a table.
  • the table can be a lookup table in the form of a key value
  • the key is the process ID of the application's main process
  • the value is the process ID list of the fork process of the application process.
  • Table 1 suppose the application is application A, and application A includes 4 processes, and the process identifiers of the 4 processes are: 6726, 6752, 6763, 8092, wherein 6726 is the process identifier of the main process, 6752 and 6763.
  • the last two columns of Table 1 record the correspondence between the application's main process and the application's fork subprocess according to the key value.
  • the above mainly describes the update mode of the packet state of the fork process of the application process when the event of the application switching from the foreground to the background occurs.
  • the fork process of the application process may be directly classified into the foreground process group, or the group state of the fork process of the application process and the parent process thereof may be The grouping status is consistent. The process is similar to the process of switching from the foreground to the background. It will not be detailed here.
  • the target process may include processes that are governed by the AMS.
  • the following describes in detail how to set at least part of the processes of such target processes to the background process group when an event of the application switching from the foreground to the background occurs.
  • the packet status of the current process to be grouped is updated based on the previous packet of the current packet of the associated process, and the specific update mode is to set the previous grouping of the associated process.
  • the grouping status of the current process is updated according to the prior art, the following problem is caused: assuming that an application switches from the foreground to the background, the current grouping of the processes in the application is updated.
  • the result of the update may be the foreground process group or the background process group.
  • the previous grouping of the current grouping of the application's process is the foreground process group, so that if the current grouping of the application process is updated to the foreground process group or the background process group, the processes associated with the application process are left in the foreground process group, and the foreground process preempts resources, causing the system card. pause.
  • step 420 may be implemented as follows: determining an associated process of the current process to be grouped by the application; the current grouping of the associated process is the foreground process group In this case, the current process is classified into the foreground process group; if the current process of the associated process is the background process group, the current process is classified into the background process group.
  • the above process can be performed in the process of updating the packet status of the current process based on the AMS.
  • the current process to be grouped by the application is a process controlled by the AMS.
  • the current process performs the AMS control process shown in FIG. 3, and the application described above is determined.
  • the association between the current process and other processes of the terminal device may be implemented by step 311 in FIG. 3. If the current process proceeds to step 311, the current process belongs to the background process group, and then the current process is updated based on the association process. The grouping status of the process.
  • the logic of the step 312 is modified to update the group status of the current process according to the current grouping of the associated process. If the current group of the associated process is the foreground process group, the current process is classified into the foreground process group; if the current group of the associated process is the background process group, the current process is classified into the background process group.
  • the embodiment of the present application updates the group status of the current process based on the current group of the association process, so that after the application is switched from the foreground to the background, the process associated with the application process also has the possibility of entering the background process group.
  • step 305 of FIG. 3 in the prior art, if the current process has a foreground service, the current process is classified into the foreground process group, and the process of placing the process in the foreground is usually implemented by the startForeground function. In other words, if too much use of the startForeground function will cause too many background application processes to stay in the foreground process group, preempt the resources with the foreground application.
  • step 420 may be implemented in the following manner: in case the current process of the application to be grouped does not include the activity in the visible state or the suspended state, according to Whether the current process is forcibly set in the foreground, updating the grouping status of the current process; if the current process is forcibly set in the foreground, the current process is classified into the foreground process group; if the current process is not forcibly set in the foreground, the current process is classified into the background Process group.
  • step 305 needs to be performed to determine whether the current process has a foreground service.
  • step 305 is not performed, and step 306 is directly executed, that is, the packet state of the current process is updated according to whether the current process is forcibly set in the foreground. This not only simplifies the AMS process group update process, but the current process does not stay in the foreground process group because it has the foreground service, which alleviates the system's stuck phenomenon.
  • FIG. 6 is a flowchart of an AMS management process according to an embodiment of the present application.
  • Steps 601-604 are similar to steps 301-304 in FIG. 3, and specifically refer to the description of FIG. 3, and are not described in detail herein.
  • the current process is classified into a background process group.
  • Steps 606-610 are similar to steps 307-311 in FIG. 3, and specifically refer to the description of FIG. 3, and are not described in detail herein.
  • Step 312 is to update the packet status of the current process according to the previous packet of the associated process.
  • step 611 is to update the group status of the current process according to the current packet of the associated process. . Specifically, in a case where the current group of the associated process is the foreground process group, the current process is classified into the foreground process group; and when the current group of the associated process is the background process group, the current process is classified into the background process group.
  • the packet state of the current process is updated based on the previous packet of the current packet of the associated process, and the specific update mode is to set the previous packet of the associated process as the current packet of the current process, if
  • the prior art method updates the packet status of the current process, which causes the following problem: assuming that an application switches from the foreground to the background, the current packet of the process in the application is updated, and the result of the update may be the foreground process group.
  • the embodiment of the present application updates the group status of the current process based on the current group of the associated process, and can Avoid the above problems, so that the application switches from the foreground to the background, and The process associated with the application process also has the possibility to enter the background process group.
  • the current process is classified into the foreground process group.
  • the method embodiment of the present application is described in detail above with reference to FIG. 1-6.
  • the device embodiment of the present application is described in detail below with reference to FIG. 7-8.
  • the device embodiment and the method embodiment correspond to each other, and the parts that are not described in detail may be See above method Example.
  • FIG. 7 is a schematic structural diagram of a terminal device according to an embodiment of the present application.
  • the terminal device 700 of FIG. 7 includes:
  • the startup unit 710 is configured to start an application in the terminal device.
  • the updating unit 720 is configured to: when an event that the application switches from the foreground to the background occurs, update a group status of the process in the application, so that at least part of the target process of the application is transferred from the foreground process group to the background A process group, where the target process is a process that still meets the conditions of the foreground process group after the application switches to the background.
  • the target process is a process that still meets the conditions of the foreground process group after the application is switched to the background. If the existing process is used, the target process will remain in the foreground process group, and the foreground process preempts resources.
  • the grouping status of the process in the application is updated, so that at least part of the processes in the target process of the application are transferred from the foreground process group to the background process group, which can reduce the preemption resources with the foreground process to some extent. The number of processes, thereby mitigating the system's stuttering phenomenon.
  • the target process includes at least one of the following processes: a fork sub-process of the process of the application; a process with an associated process, and a previous grouping of the current group of the associated process For the foreground process group; and the process that is forced to be set in the foreground.
  • the target process includes a fork sub-process of the process of the application, where the update unit 720 is specifically configured to identify the fork sub-process from multiple processes of the application;
  • the grouping state of the fork child process is such that the grouping state of the fork child process is consistent with the grouping state of the parent process of the fork child process.
  • the updating unit 720 is specifically configured to search, in the cgroup.procs file of the multiple processes, the fork sub-process, where the records of the multiple processes are recorded in a cgroup.procs file.
  • the terminal device further includes: a first determining unit, configured to determine a user identifier of the application according to a process identifier of a main process of the application; and a query unit, configured to a user identifier of the application, querying a process identifier of the multiple processes, and a second determining unit, configured to determine a cgroup.procs of the multiple processes according to the user identifier of the application and the process identifier of the multiple processes The path to the file.
  • a first determining unit configured to determine a user identifier of the application according to a process identifier of a main process of the application
  • a query unit configured to a user identifier of the application, querying a process identifier of the multiple processes
  • a second determining unit configured to determine a cgroup.procs of the multiple processes according to the user identifier of the application and the process identifier of the multiple processes The path to the file.
  • the updating unit 720 is specifically configured to determine an association process of a current process of the application to be grouped; if the current group of the association process is a foreground process group, The current process belongs to the foreground process group; if the current group of the associated process is the background process group, the current process is classified into the background process group.
  • the updating unit 720 is specifically configured to: according to whether the current process to be grouped of the application does not include an activity in a visible state or a suspended state, according to whether the current process is forced to be set In the foreground, updating the group status of the current process; if the current process is forcibly set in the foreground, the current process is classified into the foreground process group; if the current process is not forcibly set in the foreground, the current The process is grouped into a background process group.
  • FIG. 8 is a schematic structural diagram of a terminal device according to an embodiment of the present application.
  • the terminal device 800 of FIG. 8 includes:
  • a memory 810 configured to store a program
  • a processor 820 configured to execute a program stored in the memory 810, when the program is executed, the processor 820 is configured to start an application in the terminal device; when an event of the application switching from the foreground to the background occurs, Updating a grouping status of processes in the application, causing at least part of processes in the target process of the application to be transferred from the foreground process group to A background process group, the target process is a process that still meets the conditions of the foreground process group after the application switches to the background.
  • the target process is a process that still meets the conditions of the foreground process group after the application is switched to the background. If the existing process is used, the target process will remain in the foreground process group, and the foreground process preempts resources.
  • the grouping status of the process in the application is updated, so that at least part of the processes in the target process of the application are transferred from the foreground process group to the background process group, which can reduce the preemption resources with the foreground process to some extent. The number of processes, thereby mitigating the system's stuttering phenomenon.
  • the target process includes at least one of the following processes: a fork sub-process of the process of the application; a process with an associated process, and a previous grouping of the current group of the associated process For the foreground process group; and the process that is forced to be set in the foreground.
  • the target process includes a fork sub-process of the process of the application, where the processor 820 is specifically configured to identify the fork sub-process from multiple processes of the application;
  • the grouping state of the fork child process is such that the grouping state of the fork child process is consistent with the grouping state of the parent process of the fork child process.
  • the processor 820 is specifically configured to search the fork sub-process from the cgroup.procs file of the multiple processes, where the records of the cgroup.procs file of the multiple processes are recorded.
  • the processor 820 is further configured to determine a user identifier of the application according to a process identifier of a main process of the application, and query the multiple processes according to the user identifier of the application. a process identifier; determining a path of the cgroup.procs file of the multiple processes according to the user identifier of the application and the process identifier of the multiple processes.
  • the processor 820 is specifically configured to determine an association process of a current process of the application to be grouped; if the current group of the association process is a foreground process group, The current process belongs to the foreground process group; if the current group of the associated process is the background process group, the current process is classified into the background process group.
  • the processor 820 is specifically configured to: according to whether the current process to be grouped of the application does not include an activity in a visible state or a suspended state, according to whether the current process is forcibly set In the foreground, updating the group status of the current process; if the current process is forcibly set in the foreground, the current process is classified into the foreground process group; if the current process is not forcibly set in the foreground, the current The process is grouped into a background process group.
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are merely illustrative, for example, of the unit Partitioning is only a logical function partitioning. In actual implementation, there may be another way of dividing. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the functions may be stored in a computer readable storage medium if implemented in the form of a software functional unit and sold or used as a standalone product.
  • the technical solution of the present application which is essential or contributes to the prior art, or a part of the technical solution, may be embodied in the form of a software product, which is stored in a storage medium, including
  • the instructions are used to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present application.
  • the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like, which can store program codes. .

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Telephone Function (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

一种应用进程的管理方法和终端设备,包括:启动终端设备中的应用(410);当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组(420),目标进程是应用切换至后台之后,仍满足留在前台进程组的条件的进程。所述方法能够缓解前台应用的卡顿现象。

Description

应用进程的管理方法和终端设备
本申请要求于2016年09月09日提交中国专利局、申请号为201610815139.0、发明名称为“应用进程的管理方法和终端设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及终端设备领域,更为具体地,涉及一种应用进程的管理方法和终端设备。
背景技术
随着终端设备上的应用种类的增多,终端设备的使用越来越普遍。终端设备的操作系统有多种,其中,基于Linux的安卓系统是终端设备最常用的一种操作系统。
安卓系统是一个多任务的操作系统,在应用从前台切换至后台的情况下,后台应用的进程仍会继续保持运行,这样就会导致后台应用的进程与前台应用的进程争抢处理器资源,从而导致前台应用经常出现卡顿的现象。
为了缓解后台应用与前台应用争抢处理资源而引起的前台应用卡顿的问题,Google提出了基于cgroup(即control group,也可称为控制组)的前后台机制。基于cgroup的前后台机制的主要思想是将前台应用的进程尽量分在前台进程组(fore group,fg),并为前台进程组中的进程分配较多的处理资源,将后台应用的进程尽量分在后台进程组(back group,bg),并为后台进程组中的进程分配较少的处理资源。例如,前台进程组中的进程可以使用全部的处理器核,并可以占用处理器的95%的使用率;后台进程组中的进程仅可以使用一个处理器核,并最多可以占用处理器的5%的使用率。通过这样的资源分配方式,可以很大程度上缓解后台应用进程抢占前台应用进程的处理资源的问题。
但是,即使采用了基于cgroup的前后台机制,在同时运行的应用较多的情况下,前台应用仍会出现卡顿的现象。
发明内容
本申请提供一种应用进程的管理方法和终端设备,以缓解前台应用的卡顿现象。
第一方面,提供一种应用进程的管理方法,包括:启动终端设备中的应用;当所述应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态,使所述应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,所述目标进程是所述应用切换至后台之后,仍满足留在前台进程组的条件的进程。
目标进程是应用切换至后台之后,仍满足留在前台进程组的条件的进程,如果沿用现有技术,目标进程就会留在前台进程组,与前台进程抢占资源,本方案中,当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,能够一定程度上减少与前台进程抢占资源的进程 的数量,从而缓解系统的卡顿现象。
应用切换至后台之后,仍满足留在前台进程组的条件包括以下条件中的至少一个:是应用进程的fork子进程;具有前台服务;具有关联进程,且所述关联进程的当前分组的前一次分组为前台进程组。
应理解,应用进程的fork子进程可以指应用进程通过fork()函数创建的子进程。
应理解,当应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态可以指:以应用从前台切换至后台的事件为触发事件,更新所述应用中的进程的分组状态,换句话说,响应于应用从前台切换至后台的事件,更新所述应用中的进程的分组状态。
应理解,终端设备内部通过AMS不断更新进程的分组状态,当所述应用从前台切换至后台的事件发生时,受AMS管控的进程会进行分组状态的更新,从前一次分组更新至当前分组,当然,进程的前一次分组和当前分组可以是同一分组,也可以是不同分组。因此,关联进程的前一次分组可以指AMS最后一次更新关联进程的分组状态前,关联进程所属的分组,关联进程的当前分组可以指AMS最后一次更新关联进程的分组状态后,关联进程所属的分组,关联进程的前一次分组和当前分组可以相同,也可以不同。
结合第一方面,在第一方面的第一种实现方式中,所述目标进程包括以下进程中的至少一种:所述应用的进程的fork子进程;具有关联进程的进程,且所述关联进程的当前分组的前一次分组为前台进程组;以及被强制设置在前台的进程。
结合第一方面或其上述实现方式的任一种,在第一方面的第二种实现方式中,所述目标进程包含所述应用的进程的fork子进程,所述更新所述应用中的进程的分组状态,包括:从所述应用的多个进程中识别所述fork子进程;更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
现有技术中,AMS仅能管控zygote(zygote是用来创建进程的进程,可以称为孵化进程)创建的进程,无法管控应用进程的fork子进程,如果应用进程的fork子进程处于前台进程组,那么该fork子进程就会一直留在前台进程组,与前台应用的进程争抢资源,本方案基于fork子进程的父进程的分组状态更新fork子进程的分组状态,使fork子进程的分组状态与其父进程的分组状态保持一致,从而保证了fork子进程的分组状态能够得到实时更新,不会总是留在前台进程组,进一步地,将fork子进程与其父进程的分组状态保持一致,能够方便二者之间的资源共享。
结合第一方面的第二种实现方式,在第一方面的第三种实现方式中,所述从所述应用的多个进程中识别所述fork子进程,包括:从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
结合第一方面的第三种实现方式,在第一方面的第四种实现方式中,在所述从所述多个进程的cgroup.procs文件中查找所述fork子进程之前,所述方法还包括:根据所述应用的主进程的进程标识,确定所述应用的用户标识;根据所述应用的用户标识,查询所述多个进程的进程标识;根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
结合第一方面或其上述实现方式的任一种,在第一方面的第五种实现方式中,所述更新所述应用中的进程的分组状态,包括:确定所述应用的待分组的当前进程的关联进程; 在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
现有技术中,当前进程的分组状态是基于关联进程的当前分组的前一次分组进行更新的,具体更新方式是将关联进程的前一次分组设置为当前进程的当前分组,如果按照现有技术的方式对当前进程的分组状态进行更新,会引起如下问题:假设某个应用从前台切换至后台,那么该应用中的进程的当前分组会被更新,更新的结果可能是前台进程组,也可能是后台进程组,但是,由于该应用之前位于前台,那么该应用的进程的当前分组的前一次分组均是前台进程组,这样一来,如果按照现有技术的处理方式,无论该应用进程的当前分组更新为前台进程组还是后台进程组,与该应用进程相关联的进程均会被留在前台进程组,本方案基于关联进程的当前分组更新当前进程的分组状态,使得当前进程的分组与其关联进程的当前分组保持一致,能够避免上述问题的发生,使得应用从前台切换至后台,与该应用进程相关联的进程也存在进入后台进程组的可能性。
结合第一方面或其上述实现方式的任一种,在第一方面的第六种实现方式中,所述更新所述应用中的进程的分组状态,包括:在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
现有技术中,在当前进程不包含处于可见状态或暂停状态的活动的情况下,需要根据当前进程是否具有前台服务更新当前进程的分组状态,如果当前进程具有前台服务,那么会将当前进程归入前台进程组并退出当前进程的分组状态更新流程,如果当前进程不具有前台服务,会将当前进程归入后台进程组,并继续根据当前进程是否被强制设置在前台,更新当前进程的分组状态,这样的更新方式会导致具有前台服务的进程全部留在前台进程组,与前台进程抢占资源,造成系统卡顿,本方案无需根据当前进程是否具有前台服务更新当前进程的分组状态,使得当前进程不会由于具有前台服务而留在前台进程组,一定程度上缓解了系统的卡顿现象。
第二方面,提供一种应用进程的管理方法,包括:从应用的多个进程中识别所述应用进程的fork子进程;更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
现有技术中,AMS无法管控应用进程的fork子进程,如果应用进程的fork子进程处于前台进程组,那么该fork子进程就会一直留在前台进程组,与前台应用的进程争抢资源,本方案基于fork子进程的父进程的分组状态更新fork子进程的分组状态,使fork子进程的分组状态与其父进程的分组状态保持一致,从而保证了fork子进程的分组状态能够得到实时更新,不会总是留在前台进程组,进一步地,将fork子进程与其父进程的分组状态保持一致,能够方便二者之间的资源共享。
结合第二方面,在第二方面的某些实现方式中,所述从所述应用的多个进程中识别所述fork子进程,包括:从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
结合第二方面,在第二方面的某些实现方式中,在所述从所述多个进程的cgroup.procs文件中查找所述fork子进程之前,所述方法还包括:根据所述应用的主进程的进程标识, 确定所述应用的用户标识;根据所述应用的用户标识,查询所述多个进程的进程标识;根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
第三方面,提供一种应用进程的管理方法,包括:启动终端设备中的应用;当所述应用从前台切换至后台的事件发生时,确定所述应用的待分组的当前进程的关联进程;在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
现有技术中,当前进程的分组状态是基于关联进程的当前分组的前一次分组进行更新的,具体更新方式是将关联进程的前一次分组设置为当前进程的当前分组,如果按照现有技术的方式对当前进程的分组状态进行更新,会引起如下问题:假设某个应用从前台切换至后台,那么该应用中的进程的当前分组会被更新,更新的结果可能是前台进程组,也可能是后台进程组,但是,由于该应用之前位于前台,那么该应用的进程的当前分组的前一次分组均是前台进程组,这样一来,如果按照现有技术的处理方式,无论该应用进程的当前分组更为为前台进程组还是后台进程组,与该应用进程相关联的进程均会被留在前台进程组,本方案基于关联进程的当前分组更新当前进程的分组状态,使得当前进程的分组与其关联进程的当前分组保持一致,能够避免上述问题的发生,使得即使应用从前台切换至后台,与该应用进程相关联的进程也存在进入后台进程组的可能性。
第四方面,提供一种应用进程的管理方法,包括:启动终端设备中的应用;当所述应用从前台切换至后台的事件发生时,在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
现有技术中,在当前进程不包含处于可见状态或暂停状态的活动的情况下,需要根据当前进程是否具有前台服务更新当前进程的分组状态,如果当前进程具有前台服务,那么会将当前进程归入前台进程组并退出当前进程的分组状态更新流程,如果当前进程不具有前台服务,会将当前进程归入后台进程组,并继续根据当前进程是否被强制设置在前台,更新当前进程的分组状态,这样的更新方式会导致具有前台服务的进程全部留在前台进程组,与前台进程抢占资源,造成系统卡顿,本方案无需根据当前进程是否具有前台服务更新当前进程的分组状态,使得当前进程不会由于具有前台服务而留在前台进程组,一定程度上缓解了系统的卡顿现象。
第五方面,提供一种终端设备,包括用于执行第一方面至第四方面中的任一方面所描述的方法的单元。
第六方面,提供一种终端设备,包括存储器和处理器,所述存储器用于存储程序,所述处理器用于执行程序,当所述程序被执行时,所述处理器具体用于执行第一方面至第四方面中的任一方面所描述的方法。
第七方面,提供一种计算机可读介质,所述计算机可读介质用于存储程序代码,所述程序代码包含用于执行第一方面至第四方面中的任一方面所描述的方法的指令。
附图说明
图1是现有的AMS管控流程的流程图。
图2是本申请实施例提供的终端设备的框架图。
图3是本申请实施例提供的计算机系统的框架图。
图4是本申请实施例提供的应用进程的管理方法的示意性流程图。
图5是图4中的步骤420的详细流程图。
图6是本申请实施例提供的应用进程的管理方法的示意性流程图。
图7是本申请实施例提供的终端设备的示意性结构图。
图8是本申请另一实施例提供的终端设备的示意性结构图。
具体实施方式
本申请实施例提供的应用进程的管理方法主要应用于终端设备,该终端设备也可称之为用户设备(User Equipment,UE)、移动台(Mobile Station,MS)、移动终端(Mobile Terminal)等,可选的,该终端可以具备经无线接入网(Radio Access Network,RAN)与一个或多个核心网进行通信的能力,例如,终端可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等,例如,终端还可以是便携式、袖珍式、手持式、计算机内置的或者车载的移动装置。应理解的是,除了终端设备以外,本申请实施例提供的应用进程的管理方法也可以应用于其他类型的计算机系统。
请参考图1,为本申请实施例应用的终端设备的结构示意图。如图1所示,终端设备100包括存储器180、处理器150以及显示设备140。存储器180存储计算机程序,该计算机程序包括操作系统程序182和应用程序181等。处理器150用于读取存储器180中的计算机程序,然后执行计算机程序定义的方法,例如处理器150读取操作系统程序182从而在该终端设备100上运行操作系统以及实现操作系统的各种功能,或读取一种或多种应用程序181,从而在该终端设备上运行应用。
处理器150可以包括一个或多个处理器,例如,处理器150可以包括一个或多个中央处理器,或者包括一个中央处理器和一个图形处理器。当处理器150包括多个处理器时,这多个处理器可以集成在同一块芯片上,也可以各自为独立的芯片。一个处理器可以包括一个或多个处理核。
另外,存储器180还存储有除计算机程序之外的其他数据183,其他数据183可包括操作系统182或应用程序181被运行后产生的数据,该数据包括系统数据(例如操作系统的配置参数)和用户数据。
存储器180一般包括内存和外存。内存可以为随机存储器(RAM),只读存储器(ROM),以及高速缓存(CACHE)等。外存可以为硬盘、光盘、USB盘、软盘或磁带机等。计算机程序通常被存储在外存上,处理器在执行处理前会将计算机程序从外存加载到内存。
操作系统程序182中包含了可实现本申请实施例提供的应用进程的管理方法的计算机程序,从而使得处理器150读取到该操作系统程序182并运行该操作系统后,该操作系统可具备本申请实施例提供的应用进程的管理方法功能。
终端设备100还可以包括输入设备130,用于接收输入的数字信息、字符信息或接触式触摸操作/非接触式手势,以及产生与终端设备100的用户设置以及功能控制有关的信 号输入等。具体地,本申请实施例中,该输入设备130可以包括触控面板131。触控面板131,也称为触摸屏,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触控面板131上或在触控面板131的操作),并根据预先设定的程式驱动相应的连接装置。可选的,触控面板131可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给该处理器150,并能接收处理器150发来的命令并加以执行。
触控面板131可以采用电阻式、电容式、红外线以及表面声波等多种类型实现。除了触控面板131,输入设备130还可以包括其他输入设备132,其他输入设备132可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。
终端设备100还可以包括显示设备140,显示设备140,包括显示面板141,用于显示由用户输入的信息或提供给用户的信息以及终端设备100的各种菜单界面等,在本申请实施例中主要用于处于前台的应用进程或终端设备的桌面。该显示设备140可包括显示面板141,可选的,可以采用LCD(Liquid Crystal Display,液晶显示器)或OLED(Organic Light-Emitting Diode,有机发光二极管)等形式来配置显示面板141。在其他一些实施例中,触控面板131可覆盖显示面板141上,形成触摸显示屏。
除以上之外,终端设备100还可以包括用于给其他模块供电的电源190以及用于拍摄照片或视频的摄像头160。终端设备100还可以包括一个或多个传感器120,例如加速度传感器、光传感器等。终端设备100还可以包括无线射频(Radio Frequency,RF)电路110,用于与无线网络设备进行网络通信,还可以包括WiFi模块170,用于与其他设备进行WiFi通信。
本申请实施例提供的应用进程的管理方法可以实现在图1所示的操作系统182中。该操作系统可以为Android操作系统,下面结合图2,以Android操作系统为例,介绍本申请实施例提供的方法的实现位置。
请参阅图2,为本申请实施例提供的计算机系统200的结构示意图。该计算机系统可以是终端设备,包括应用层210和操作系统层250,该操作系统可以为Android操作系统。操作系统层250又分为框架层220、核心库层230和驱动层240。其中,图2中的操作系统层250可以认为是图1中操作系统182的一种具体实现,图2中的应用层210可以认为是图1中应用程序181的一种具体实现。驱动层240包括CPU驱动241、GPU驱动242以及显示控制器驱动243等。核心库层230是操作系统的核心部分,包括输入/输出服务231、核心服务232、图形设备接口234以及实现CPU或GPU图形处理的图形引擎(Graphics Engine)233等。图形引擎233可包括2D引擎、3D引擎、合成器(Composition)、帧缓冲区(Frame Buffer)、EGL(Embedded-System Graphics Library)等,其中EGL是一种渲染API与底层原始平台窗口系统之间的接口,API指的是应用程序编程接口(Application Programming Interface)。框架层220可包括图形服务(Graphic Service)224、系统服务(System service)221、网页服务(Web Service)222和用户服务(Customer Service)223等;图形服务224中,可包括如微件(Widget)、画布(Canvas)以及视图(Views)等。应用层210可包括图库211、媒体播放器(Media Player)212以及浏览器(Browser)213 等。
另外,在驱动层240之下,该计算机系统200还包括硬件层250。该计算机系统200的硬件层可以包括中央处理器(Central Processing Unit,CPU)251和图形处理器(Graphic Processing Unit,GPU)252(相当于图1中的处理器150的一种具体实现),还可以包括存储器253(相当于图1中的存储器180),包括内存和外存,还可以包括输入设备254(相当于图1中的输入设备132)、显示设备255(相当于图1中的显示设备140),例如液晶显示器(Liquid Crystal Display,LCD)、全息成像(Holographic)、投影(Projector)等,还可以包括一个或多个传感器256(相当于图1中的传感器120)。当然除此之外,硬件层250还可以包括图1中示出的电源、摄像头、RF电路和WiFi模块,还可以包括图1中也没有示出的其他硬件模块,例如内存控制器和显示控制器等。
本申请实施例提供的应用进程的管理方法可以在图2中的操作系统执行层250中实现。
上文指出,现有技术为了缓解前台应用的卡顿现象,引入了基于cgroup的前后台机制。但是,即使引入该前后台机制,当同时运行的应用较多时,前台应用仍会出现卡顿现象,经过研究发现,这种卡顿现象是由于应用切换至后台以后,应用中的部分进程仍满足留在前台进程组的条件而造成的。也就是说,现有技术中,即使应用切换至后台,由于某些进程仍满足留在前台进程组的条件,它们就会留在前台进程组,与前台应用的进程抢占资源,从而导致前台应用出现卡顿现象。
为了便于描述,下文将“应用切换至后台之后,仍满足留在前台进程组的条件的进程”称为应用的目标进程,需要说明的是,本申请实施例对目标进程的类型不作具体限定,下面进行举例说明。
在一些实施例中,目标进程可以包括不受活动管理服务(Activity Manager Service,AMS)管控的进程,如应用进程的fork子进程。下面分析应用切换至后台之后,这种类型的进程会留在前台进程组的原因。AMS是操作系统的重要组成部分,主要提供以下主要功能:统一调度各应用的活动(Activity);内存管理;以及进程管理。AMS属于图2中的系统服务221的一部分。
基于cgroup的前后台分组机制是在AMS的管控之下进行的,即由AMS来更新进程的分组状态。但是,AMS仅能管控zygote(zygote是用来创建进程的进程,可以称为孵化进程)创建的进程,应用进程的fork子进程(即应用进程以fork方式创建的子进程,或者,应用本身通过fork()调用产生的子进程)不受AMS的管控,这样会导致应用进程的fork子进程的分组状态无法得到更新,这样就会导致某些fork子进程始终留在前台进程组。
在一些实施例中,目标进程可以包括受AMS管控的进程,如具有前台服务的进程、被强制设置在前台的进程等。
具体地,在现有的AMS管控流程中,当应用前后台切换事件发生时,AMS会基于一定的条件和逻辑更新受AMS管控的进程的分组状态。换句话说,应用前后台切换事件发生时,满足某些条件的进程会随着应用切换至后台而进入后台进程组,但满足某些条件的进程会留在前台进程组,如前文提到的具有前台服务的进程。为了便于理解,先结合图3,介绍现有的AMS管控流程。
图3是现有的AMS管控流程的流程图,AMS会基于图3所示的管控流程对受其管控的进程的分组状态进行更新。
301、确定应用从前台切换至后台。
应理解,除了应用从前台切换至后台这一事件之外,还有许多其它事件可能会触发AMS的管控流程。例如,应用启动事件、应用从后台切换至前台事件、进程接收广播事件等。
302、判断当前进程是否为前台进程或正在接收广播的进程。
如果当前进程是前台进程或正在接收广播的进程,执行步骤313,将其归入前台进程组并退出;如果当前进程不是前台进程,也不是正在接收广播的进程,执行步骤303。
应理解,在步骤301对应的事件发生时,受AMS管控的进程一般均会按照图3所示的流程进行进程组的更新,步骤302中的当前进程指终端设备中的受AMS管控的某个进程,且该进程正在通过图3的流程进行分组状态的更新。
303、将当前进程所属的进程组设置为后台进程组。
304、判断当前进程是否包含可见状态或暂停状态的活动。
安卓系统定义了四大组件,分别是活动(activity)、服务(service)、内容提供者(content provider)以及广播接收器(broadcast receiver)。
活动通常是一个单独的窗口,活动之间会通过Intent进行通信。进一步地,活动一般包括四种基本状态:激活状态或运行状态(active or running)、暂停状态(paused)、停止状态(stop)以及被杀状态(killed)。
在步骤304中,如果当前进程包含可见状态或暂停状态的活动,执行步骤313,将其归入前台进程组并退出(即结束当前进程的分组状态更新流程);如果当前进程不包含可见状态或暂停状态的活动,执行步骤305。
305、判断当前进程是否具有前台服务。
服务一般是一段生命周期长、没有用户界面的程序,该程序通常在后台运行。位于后台的服务优先级低,存在被杀掉的可能,因此,有些应用会通过startForeground函数让服务在前台运行。
如果当前进程具有前台服务,执行步骤313,将其归入前台进程组并退出;如果当前进程不具有前台服务,执行步骤306。
306、判断当前进程是否被强制设置在前台。
有些应用为了保证其某些进程不被杀掉,会通过setProcessForeground函数,将这些进程强制设置在前台。如果当前进程被强制设置在前台,执行步骤313,将其归入前台进程组并退出;如果当前进程未被强制设置在前台,执行步骤307。
307、判断当前进程是否具有Heavy Weight属性(重量级属性)。
具有Heavy Weight属性的进程即使放在后台,也不容易被杀掉。因此,在步骤307中,如果进程具有Heavy Weight属性,则执行步骤310,将其归入后台进程组;如果进程不具有Heavy Weight属性,则执行步骤308。
308、判断当前进程是否为桌面进程。
如果当前进程为桌面进程,执行步骤310,将其归入后台进程组;如果当前进程不为桌面进程,则执行步骤309。
309、判断当前进程是否为前一个处于前台的应用的进程。
如果当前进程为前一个处于前台的应用的进程,执行步骤310,将其归入后台进程组;如果当前进程不为前一个处于前台的应用的进程,则执行步骤311。应理解,根据用户的操作,处于前台的应用是在不断变化的,例如,用户首先启动应用A,则应用A处于前台,接着,用户又启动应用B,此时,应用B成为前台应用,此时,应用A成为前一个处于前台的应用;接下来,如果用户按下HOME键,使得应用B从前台切换至后台,那么应用B就变成前一个处于前台的应用。
310、将当前进程归入后台进程组。
311、确定当前进程是否具有关联进程。
具体地,可以通过判断当前进程是否有正在运行的服务或者内容提供者(通过内容提供者可以将一个应用程序的指定数据集提供给其它应用使用,即通过内容提供者可以实现应用之间的数据共享)来判断当前进程是否具有关联进程。
如果当前进程具有正在运行的服务或内容提供者,表明当前进程具有关联进程,执行步骤312;否则直接退出。
312、根据关联进程的前一次分组更新当前进程的分组状态。
具体地,假设关联进程前一次分组为前台进程组,则将当前进程归入前台进程组;假设关联进程前一次分组为后台进程组,则将当前进程归入后台进程组,即将当前进程的当前分组与关联进程的前一次分组保持一致。
应理解,终端设备内部通过AMS不断更新进程的分组状态,当所述应用从前台切换至后台的事件发生时,受AMS管控的进程会进行分组状态的更新,从前一次分组更新至当前分组,当然,进程的前一次分组和当前分组可以是同一分组,也可以是不同分组。因此,关联进程的前一次分组可以指AMS最后一次更新关联进程的分组状态前,关联进程所属的分组,关联进程的当前分组可以指AMS最后一次更新关联进程的分组状态后,关联进程所属的分组,关联进程的前一次分组和当前分组可以相同,也可以不同。
313、将当前进程归入前台进程组。
从图3的流程可以看出,应用切换至后台以后,该应用中的受AMS管控的某些进程会由于满足图3流程中的某些条件而被留在前台进程组,本申请实施例的目标进程可以包括这种类型的目标进程。例如,目标进程可以包括以下进程中的至少一种:具有关联进程的进程,且关联进程的当前分组的前一次分组为前台进程组;具有前台服务的进程;以及被强制设置在前台的进程。
为了缓解后台应用的进程与前台应用的进程抢占资源的现象,当应用从前台切换至后台的事件发生时,可以通过一定方式将目标进程中的部分或全部进程设置到后台进程组。下面结合图4,详细描述本申请实施例的应用进程的管理方法。
图4是本申请实施例的应用进程的管理方法的示意性流程图。图4的方法可以由终端设备执行,具体可以由终端设备的操作系统执行,如图2中的操作系统层250。图4的方法包括:
410、启动终端设备中的应用。
具体地,上述应用(APP)可以指终端设备中的当前正在运行的应用。例如,可以是终端设备当前打开的购物应用,音乐应用或社交网络应用等。
420、当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组。
如前文所述,目标进程是应用切换至后台之后,仍满足留在前台进程组的条件的进程,如果沿用现有技术,目标进程就会留在前台进程组,与前台进程抢占资源,本申请实施例当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,能够一定程度上缓解目标进程与前台进程抢占资源的现象。
需要说明的是,目标进程可以包括不受AMS管控的进程,如应用的进程的fork子进程;或者,目标进程可以包括受AMS管控的进程,如应用中的具有关联进程的进程,且关联进程的当前分组的前一次分组为前台进程组,应用中的具有前台服务的进程,或者应用中的被强制设置在前台的进程。不同类型的目标进程对应的步骤420的执行方式可以不同,下面结合具体的实施例进行详细描述。
可选地,在一些实施例中,目标进程包含应用的进程的fork子进程,步骤420可包括:从应用的多个进程中识别应用进程的fork子进程;将fork子进程所属的进程组设置为后台进程组。
例如,应用包括进程1、进程2、进程3和进程4,其中,进程2和进程3是识别出的fork子进程,此时,进程1和进程4可以基于AMS更新其所属的进程组,而进程2和进程3所属的进程组可以直接设置为后台进程组。
本申请实施例将识别出的fork子进程直接转移至后台进程组,操作简单,易于实现。
可选地,在另一些实施例中,如图5所示,目标进程包含应用的进程的fork子进程(分叉子进程),步骤420可包括:
422、从应用的多个进程中识别应用进程的fork子进程。
424、更新fork子进程的分组状态,使fork子进程的分组状态与fork子进程的父进程的分组状态保持一致。
本申请实施例基于fork子进程的父进程的分组状态更新fork子进程的分组状态,使fork子进程的分组状态与其父进程的分组状态保持一致,从而保证了fork子进程的分组状态能够得到实时更新,进一步地,将fork子进程与其父进程的分组状态保持一致,能够方便二者之间的资源共享。
具体地,步骤424可包括:通过AMS更新应用中的除该fork子进程之外的剩余进程的分组状态;根据该剩余进程的分组状态更新fork子进程的分组状态,使fork子进程的分组状态与fork子进程的父进程的分组状态保持一致。
需要说明的是,本申请实施例中,虽然fork子进程的分组状态的更新需要基于除fork子进程之外的剩余进程的分组状态的更新,但本实施例并不限定要将剩余进程的分组状态全部更新完毕,再去更新fork子进程的分组状态,既可以将剩余进程的分组状态全部更新完毕,再去更新fork子进程的分组状态,也可以将二者交叉进行。举例说明,假设应用包括进程1、进程2、进程3和进程4,其中,进程3和进程4是识别出的fork子进程,进程1是进程3的父进程,进程2是进程4的父进程,则进程1和进程2是除fork子进程之外的剩余进程。一种可行的更新方式:先基于AMS更新进程1和进程2的分组状态,然后更新进程3和进程4的分组状态,使其分别与进程1和进程2的分组状态保持一致;另 一种可行的更新方式:先基于AMS更新进程1的分组状态,然后更新进程3的分组状态,使其与进程1的分组状态保持一致,再基于AMS更新进程2的分组状态,然后更新进程4的分组状态,使其与进程2的分组状态保持一致。
进一步地,在一些实施例中,如果某个fork子进程(下称第一fork子进程)的父进程也是fork子进程(下称第二fork子进程),且第二fork子进程的父进程是受AMS管控的进程,则可以先基于AMS更新第二fork子进程的父进程的分组状态,然后再更新第二fork子进程的分组状态,使第二fork子进程的分组状态与其父进程的分组状态保持一致,然后再更新第一fork子进程的分组状态,使第一fork子进程的分组状态与第二fork子进程的分组状态保持一致。
进一步地,将fork子进程的分组状态与其父进程的分组状态保持一致的方式有多种,例如,可以调用setProcessGroup函数调节fork子进程的进程组,使fork子进程的进程组与其父进程的进程组保持一致。
应理解,步骤422的实现方式可以有多种,可选地,作为一种实现方式,可以预先记录应用进程的fork子进程,例如,可以预先建立fork子进程的记录表,应用每fork出一个子进程,就在该记录表中记录该子进程的进程标识,需要使用时,可以查找该记录表,从而识别fork子进程。
可选地,作为另一种实现方式,步骤422可包括:从多个进程的cgroup.procs文件中查找fork子进程,其中,多个进程的cgroup.procs文件中记录了fork子进程的进程标识。
具体地,cgroup.procs文件是cgroup机制支持的一种文件类型,一个进程对应一个cgroup.procs文件,该cgroup.procs文件中记录了该进程的进程标识,以及该进程的fork子进程的进程标识。一个进程对应的cgroup.procs文件通常位于如下文件路径:/acct/uid_xxx/pid_xxx/cgroup.procs,其中,uid_xxx表示应用的用户标识,pid_xxx表示该进程的进程标识
假设应用包括进程1、进程2、进程3以及进程4,其中,进程1的cgroup.procs文件记录了进程1的进程标识和进程3的进程标识,则进程3为进程1的fork子进程;进程2的cgroup.procs文件记录了进程2的进程标识,则进程2没有fork子进程;进程3的cgroup.procs文件记录了进程3的进程标识和进程4的进程标识,则进程4为进程3的fork子进程;进程4的cgroup.procs文件记录了进程4的标识,则进程4没有fork子进程。综上可知,从以上4个进程的cgroup.procs文件中查询出的fork子进程为进程3和进程4。
需要说明的是,并不是应用的每个进程均会有fork子进程,因此,为了简化实现,步骤422可以采用如下方式进行:先查询某个进程的cgroup.procs文件中记录的进程数,如果进程数大于1,说明该进程具有fork子进程;如果进程数为1,说明该进程不具有fork子进程,继续查询下一个进程的cgroup.procs文件,直到所有进程的cgroup.procs文件均查询完毕。
在一些实施例中,可以先确定应用的多个进程的cgroup.procs文件的路径,再从中查找应用进程的fork子进程。具体地,应用的多个进程的cgroup.procs文件的路径可以通过如下方式获得:根据应用的主进程的进程标识,确定应用的用户标识;根据应用的用户标识,查询多个进程的进程标识;根据应用的用户标识,以及多个进程的进程标识,确定多个进程的cgroup.procs文件的路径。
具体地,每个应用具有一个用户标识(uid),用于唯一标识该应用。应用的用户标识的获取方式有多种,例如,可以通过查询应用的配置信息,确定该应用的用户标识;又如,可以根据应用的主进程标识,确定该应用的用户标识,例如,可以调用如下函数:process.getUidForPid(pid_main)来获取应用的用户标识,其中,pid_main表示应用的主进程标识,该函数返回的结果为应用的用户标识。
应用的多个进程的进程标识的获取方式可以有多种,例如,可以先获取应用的用户标识uid_xxx,然后在/acct/uid_xxx文件中找到该应用包含的进程的进程标识;又如,可以预先建立应用进程的进程标识记录表,应用每生成一个进程,就在该记录表中记录该进程的进程标识,需要使用时,可以通过该记录表获得应用进程的进程标识。
在一些实施例中,考虑到应用进程的fork子进程产生的延迟性,可以预先设置一个计数值以及计数值阈值,该计数值指示应用进程的fork子进程的查询次数,当应用从前台切换至后台的事件发生时,如果计数值小于计数阈值,则从应用进程的cgroup.procs文件查询应用进程的fork子进程;如果计数值大于或等于计数阈值,则认为应用的fork子进程基本保持不变,可以重复使用上一次的查询结果,以加快fork子进程的识别速度。
在一些实施例中,为了便于查询,应用进程的fork子进程可以通过表格的方式进行记录。
例如,该表格可以是键值形式的对照表,键为应用的主进程的进程标识,值为应用进程的fork子进程的进程标识列表。以表一为例,假设应用为应用A,应用A包括4个进程,该4个进程的进程标识依次为:6726,6752,6763,8092,其中,6726为主进程的进程标识,6752和6763为应用进程的fork子进程的进程标识,表一的后两列按照键值方式记录了应用的主进程与应用进程的fork子进程的对应关系
表一
Figure PCTCN2017100444-appb-000001
上文主要描述的是应用从前台切换至后台的事件发生时,应用进程的fork子进程的分组状态的更新方式。进一步地,在一些实施例中,应用从后台切换至前台的事件发生时,可以直接将应用进程的fork子进程归入前台进程组,或者将应用进程的fork子进程的分组状态与其父进程的分组状态保持一致,具体过程与应用从前台切换至后台的过程类似,此处不再详述。
可选地,在一些实施例中,目标进程可以包括受AMS管控的进程。下面详细描述当应用从前台切换至后台的事件发生时,如何将这类目标进程中的至少部分进程设置到后台进程组。
从图3的步骤312可以看出,现有技术中,待分组的当前进程的分组状态是基于关联进程的当前分组的前一次分组进行更新的,具体更新方式是将关联进程的前一次分组设置 为当前进程的当前分组,如果按照现有技术的方式对当前进程的分组状态进行更新,会引起如下问题:假设某个应用从前台切换至后台,那么该应用中的进程的当前分组会被更新,更新的结果可能是前台进程组,也可能是后台进程组,但是,由于该应用之前位于前台,那么该应用的进程的当前分组的前一次分组均是前台进程组,这样一来,如果按照现有技术的处理方式,无论该应用进程的当前分组更新为前台进程组还是后台进程组,与该应用进程相关联的进程均会被留在前台进程组,与前台进程抢占资源,造成系统卡顿。
本申请实施例中的目标进程可以包括这种因关联关系而留在前台进程组的进程。为了缓解这种类型的目标进程留在前台而引起的系统卡顿现象,可以通过如下方式实现步骤420:确定应用的待分组的当前进程的关联进程;在关联进程的当前分组为前台进程组的情况下,将当前进程归入前台进程组;在关联进程的当前分组为后台进程组的情况下,将当前进程归入后台进程组。
应理解,上述过程可以在基于AMS更新当前进程的分组状态的过程中进行。具体地,应用的待分组的当前进程是受AMS管控的进程,当应用从前台切换至后台的事件发生时,该当前进程会执行图3所示的AMS管控流程,上文描述的确定应用的当前进程与终端设备的其他进程具有关联关系可以由图3中的步骤311实现,如果当前进程执行到步骤311,说明当前进程目前属于后台进程组,接下来会通过步骤312,基于关联进程更新当前进程的分组状态。为了避免上文指出的因关联关系导致的某些后台应用的进程留在前台进程组的问题,本申请实施例将步骤312的逻辑修改为:根据关联进程的当前分组,更新当前进程的分组状态,在关联进程的当前分组为前台进程组的情况下,将当前进程归入前台进程组;在关联进程的当前分组为后台进程组的情况下,将当前进程归入后台进程组。
本申请实施例基于关联进程的当前分组更新当前进程的分组状态,使得应用从前台切换至后台之后,与该应用进程相关联的进程也存在进入后台进程组的可能性。
从图3的步骤305可以看出,现有技术中,如果当前进程具有前台服务,则当前进程会被归入前台进程组,而将进程的服务置于前台通常是通过startForeground函数实现的。换句话说,如果过多的使用startForeground函数会导致过多的后台应用的进程留在前台进程组,与前台应用抢占资源。
本申请实施例中的目标进程可以包括这种由于具有前台服务而留在前台进程组的进程。为了缓解这种类型的目标进程留在前台而引起的系统卡顿问题,可以采用如下方式实现步骤420:在应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据当前进程是否被强制设置在前台,更新当前进程的分组状态;如果当前进程被强制设置在前台,将当前进程归入前台进程组;如果当前进程未被强制设置在前台,将当前进程归入后台进程组。
应理解,上述过程可以在基于AMS更新当前进程的分组状态的过程中进行。具体地,从图3可以看出,现有技术中,如果当前进程不包含处于可见状态或暂停状态的活动,需要执行步骤305,即判断当前进程是否具有前台服务。而在本申请实施例中,如果当前进程不包含处于可见状态或暂停状态的活动,无需执行步骤305,直接执行步骤306,即根据当前进程是否被强制设置在前台,更新当前进程的分组状态。这样不但简化了AMS的进程组更新流程,而且当前进程不会因为其具有前台服务而留在前台进程组,缓解了系统的卡顿现象。
下面结合具体例子,更加详细地描述本申请实施例。应注意,图6的例子仅仅是为了帮助本领域技术人员理解本申请实施例,而非要将本申请实施例限于所例示的具体数值或具体场景。本领域技术人员根据所给出的图6的例子,显然可以进行各种等价的修改或变化,这样的修改或变化也落入本申请实施例的范围内。
图6是本申请实施例的AMS管控流程的流程图。
601、确定应用从前台切换至后台。
602、判断当前进程是否为前台进程或正在接收广播的进程。
603、将当前进程所属的进程组设置为后台进程组。
604、判断当前进程是否包含可见状态或暂停状态的活动。
步骤601-604与图3中的步骤301-304类似,具体参见图3的描述,此处不再详述。
605、判断当前进程是否被强制设置在前台。
对比图6和图3可以看出,在图6的实施例中,在当前进程不包含处于可见状态或暂停状态的活动的情况下,无需判断当前进程是否具有前台服务,直接根据当前进程是否被强制设置在前台,更新当前进程的分组状态。这样能够避免具有前台服务的进程留在前台,与前台应用抢占资源。
606、判断当前进程是否具有Heavy Weight属性。
607、判断当前进程是否为桌面进程。
608、判断当前进程是否为前一个处于前台的应用的进程。
609、将当前进程归入后台进程组。
610、确定当前进程是否具有关联进程。
步骤606-610与图3中的步骤307-311类似,具体参见图3的描述,此处不再详述。
611、根据关联进程的当前分组更新当前进程的分组状态。
该步骤对应于图3中的步骤312,步骤312是根据关联进程的前一次分组更新当前进程的分组状态,与步骤312不同的是,步骤611是根据关联进程的当前分组更新当前进程的分组状态。具体地,在关联进程的当前分组为前台进程组的情况下,将当前进程归入前台进程组;在关联进程的当前分组为后台进程组的情况下,将当前进程归入后台进程组。
图3描述的现有技术中,当前进程的分组状态是基于关联进程的当前分组的前一次分组进行更新的,具体更新方式是将关联进程的前一次分组设置为当前进程的当前分组,如果按照现有技术的方式对当前进程的分组状态进行更新,会引起如下问题:假设某个应用从前台切换至后台,那么该应用中的进程的当前分组会被更新,更新的结果可能是前台进程组,也可能是后台进程组,但是,由于该应用之前位于前台,那么该应用的进程的当前分组的前一次分组均是前台进程组,这样一来,如果按照现有技术的处理方式,无论该应用进程的当前分组更新为前台进程组还是后台进程组,与该应用进程相关联的进程均会被留在前台进程组,本申请实施例基于关联进程的当前分组更新当前进程的分组状态,能够避免上述问题的发生,使得应用从前台切换至后台,与该应用进程相关联的进程也存在进入后台进程组的可能性。
612、将当前进程归入前台进程组。
上文结合图1-6,详细描述了本申请的方法实施例,下文结合图7-8,详细描述本申请的装置实施例,装置实施例与方法实施例相互对应,未详细描述的部分可以参见上述方法 实施例。
图7是本申请实施例的终端设备的示意性结构图。图7的终端设备700包括:
启动单元710,用于启动终端设备中的应用;
更新单元720,用于当所述应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态,使所述应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,所述目标进程是所述应用切换至后台之后,仍满足留在前台进程组的条件的进程。
目标进程是应用切换至后台之后,仍满足留在前台进程组的条件的进程,如果沿用现有技术,目标进程就会留在前台进程组,与前台进程抢占资源,本申请实施例中,当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,能够一定程度上减少与前台进程抢占资源的进程的数量,从而缓解系统的卡顿现象。
可选地,作为一个实施例,所述目标进程包括以下进程中的至少一种:所述应用的进程的fork子进程;具有关联进程的进程,且所述关联进程的当前分组的前一次分组为前台进程组;以及被强制设置在前台的进程。
可选地,作为一个实施例,所述目标进程包含所述应用的进程的fork子进程,所述更新单元720具体用于从所述应用的多个进程中识别所述fork子进程;更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
可选地,作为一个实施例,所述更新单元720具体用于从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
可选地,作为一个实施例,所述终端设备还包括:第一确定单元,用于根据所述应用的主进程的进程标识,确定所述应用的用户标识;查询单元,用于根据所述应用的用户标识,查询所述多个进程的进程标识;第二确定单元,用于根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
可选地,作为一个实施例,所述更新单元720具体用于确定所述应用的待分组的当前进程的关联进程;在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
可选地,作为一个实施例,所述更新单元720具体用于在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
图8是本申请实施例的终端设备的示意性结构图。图8的终端设备800包括:
存储器810,用于存储程序;
处理器820,用于执行存储器810中存储的程序,当所述程序被执行时,所述处理器820用于启动终端设备中的应用;当所述应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态,使所述应用的目标进程中的至少部分进程从前台进程组转移至 后台进程组,所述目标进程是所述应用切换至后台之后,仍满足留在前台进程组的条件的进程。
目标进程是应用切换至后台之后,仍满足留在前台进程组的条件的进程,如果沿用现有技术,目标进程就会留在前台进程组,与前台进程抢占资源,本申请实施例中,当应用从前台切换至后台的事件发生时,更新应用中的进程的分组状态,使应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,能够一定程度上减少与前台进程抢占资源的进程的数量,从而缓解系统的卡顿现象。
可选地,作为一个实施例,所述目标进程包括以下进程中的至少一种:所述应用的进程的fork子进程;具有关联进程的进程,且所述关联进程的当前分组的前一次分组为前台进程组;以及被强制设置在前台的进程。
可选地,作为一个实施例,所述目标进程包含所述应用的进程的fork子进程,所述处理器820具体用于从所述应用的多个进程中识别所述fork子进程;更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
可选地,作为一个实施例,所述处理器820具体用于从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
可选地,作为一个实施例,所述处理器820还用于根据所述应用的主进程的进程标识,确定所述应用的用户标识;根据所述应用的用户标识,查询所述多个进程的进程标识;根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
可选地,作为一个实施例,所述处理器820具体用于确定所述应用的待分组的当前进程的关联进程;在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
可选地,作为一个实施例,所述处理器820具体用于在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的 划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。

Claims (14)

  1. 一种应用进程的管理方法,其特征在于,包括:
    启动终端设备中的应用;
    当所述应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态,使所述应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,所述目标进程是所述应用切换至后台之后,仍满足留在前台进程组的条件的进程。
  2. 如权利要求1所述的方法,其特征在于,所述目标进程包括以下进程中的至少一种:
    所述应用的进程的fork子进程;
    具有关联进程的进程,且所述关联进程的当前分组的前一次分组为前台进程组;以及
    被强制设置在前台的进程。
  3. 如权利要求1或2所述的方法,其特征在于,所述目标进程包含所述应用的进程的fork子进程,
    所述更新所述应用中的进程的分组状态,包括:
    从所述应用的多个进程中识别所述fork子进程;
    更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
  4. 如权利要求3所述的方法,其特征在于,所述从所述应用的多个进程中识别所述fork子进程,包括:
    从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
  5. 如权利要求4所述的方法,其特征在于,在所述从所述多个进程的cgroup.procs文件中查找所述fork子进程之前,所述方法还包括:
    根据所述应用的主进程的进程标识,确定所述应用的用户标识;
    根据所述应用的用户标识,查询所述多个进程的进程标识;
    根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
  6. 如权利要求1或2所述的方法,其特征在于,所述更新所述应用中的进程的分组状态,包括:
    确定所述应用的待分组的当前进程的关联进程;
    在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;
    在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
  7. 如权利要求1或2所述的方法,其特征在于,所述更新所述应用中的进程的分组状态,包括:
    在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根 据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;
    如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;
    如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
  8. 一种终端设备,其特征在于,包括:
    启动单元,用于启动终端设备中的应用;
    更新单元,用于当所述应用从前台切换至后台的事件发生时,更新所述应用中的进程的分组状态,使所述应用的目标进程中的至少部分进程从前台进程组转移至后台进程组,所述目标进程是所述应用切换至后台之后,仍满足留在前台进程组的条件的进程。
  9. 如权利要求8所述的终端设备,其特征在于,所述目标进程包括以下进程中的至少一种:
    所述应用的进程的fork子进程;
    具有关联进程的进程,且所述关联进程的当前分组的前一次分组为前台进程组;以及
    被强制设置在前台的进程。
  10. 如权利要求8或9所述的终端设备,其特征在于,所述目标进程包含所述应用的进程的fork子进程,
    所述更新单元具体用于从所述应用的多个进程中识别所述fork子进程;更新所述fork子进程的分组状态,使所述fork子进程的分组状态与所述fork子进程的父进程的分组状态保持一致。
  11. 如权利要求10所述的终端设备,其特征在于,所述更新单元具体用于从所述多个进程的cgroup.procs文件中查找所述fork子进程,其中,所述多个进程的cgroup.procs文件中记录了所述fork子进程的进程标识。
  12. 如权利要求11所述的终端设备,其特征在于,所述终端设备还包括:
    第一确定单元,用于根据所述应用的主进程的进程标识,确定所述应用的用户标识;
    查询单元,用于根据所述应用的用户标识,查询所述多个进程的进程标识;
    第二确定单元,用于根据所述应用的用户标识,以及所述多个进程的进程标识,确定所述多个进程的cgroup.procs文件的路径。
  13. 如权利要求8或9所述的终端设备,其特征在于,所述更新单元具体用于确定所述应用的待分组的当前进程的关联进程;在所述关联进程的当前分组为前台进程组的情况下,将所述当前进程归入前台进程组;在所述关联进程的当前分组为后台进程组的情况下,将所述当前进程归入后台进程组。
  14. 如权利要求8或9所述的终端设备,其特征在于,所述更新单元具体用于在所述应用的待分组的当前进程不包含处于可见状态或暂停状态的活动的情况下,根据所述当前进程是否被强制设置在前台,更新所述当前进程的分组状态;如果所述当前进程被强制设置在前台,将所述当前进程归入前台进程组;如果所述当前进程未被强制设置在前台,将所述当前进程归入后台进程组。
PCT/CN2017/100444 2016-09-09 2017-09-05 应用进程的管理方法和终端设备 WO2018045934A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP17848107.3A EP3506093A4 (en) 2016-09-09 2017-09-05 METHOD OF MANAGING AN APPLICATION PROCESS AND TERMINAL DEVICE
US16/296,503 US20190205160A1 (en) 2016-09-09 2019-03-08 Application Process Management Method And Terminal Device

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610815139.0 2016-09-09
CN201610815139.0A CN107807847B (zh) 2016-09-09 2016-09-09 应用进程的管理方法和终端设备

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US16/296,503 Continuation US20190205160A1 (en) 2016-09-09 2019-03-08 Application Process Management Method And Terminal Device

Publications (1)

Publication Number Publication Date
WO2018045934A1 true WO2018045934A1 (zh) 2018-03-15

Family

ID=61561649

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/100444 WO2018045934A1 (zh) 2016-09-09 2017-09-05 应用进程的管理方法和终端设备

Country Status (4)

Country Link
US (1) US20190205160A1 (zh)
EP (1) EP3506093A4 (zh)
CN (1) CN107807847B (zh)
WO (1) WO2018045934A1 (zh)

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108920263B (zh) * 2018-06-08 2020-10-13 上海连尚网络科技有限公司 用于应用保持的方法与设备
CN110096348A (zh) * 2019-03-29 2019-08-06 努比亚技术有限公司 后台应用控制方法、可穿戴设备及计算机可读存储介质
CN110806926A (zh) * 2019-09-05 2020-02-18 华为技术有限公司 一种资源管控方法及设备
CN112506629B (zh) * 2020-11-27 2023-08-22 努比亚技术有限公司 一种系统调度优化方法、终端及计算机可读存储介质
CN116244067B (zh) * 2021-06-10 2024-05-03 荣耀终端有限公司 虚拟内存管理方法和电子设备
CN113791888A (zh) * 2021-11-17 2021-12-14 北京鲸鲮信息系统技术有限公司 Linux应用进程管理方法及装置
CN114579200A (zh) * 2022-02-28 2022-06-03 联想(北京)有限公司 一种数据处理方法及装置
CN114968551B (zh) * 2022-03-10 2023-09-19 中移互联网有限公司 一种进程管理的方法、装置、电子设备及存储介质
CN117707718A (zh) * 2023-06-29 2024-03-15 荣耀终端有限公司 进程管理的方法、电子设备及可读存储介质
CN117707719A (zh) * 2023-06-29 2024-03-15 荣耀终端有限公司 进程管理的方法、电子设备及可读存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080189708A1 (en) * 2007-02-02 2008-08-07 Ibm Corporation Method and apparatus for preventing undesired termination of a process in an information handling system
CN103443770A (zh) * 2011-03-19 2013-12-11 富士通株式会社 终端装置、进程管理方法以及进程管理程序
CN104050035A (zh) * 2014-05-14 2014-09-17 小米科技有限责任公司 应用程序的处理方法及装置
CN104252389A (zh) * 2013-06-27 2014-12-31 腾讯科技(深圳)有限公司 应用程序运行方法、系统及应用程序
CN105045669A (zh) * 2015-08-26 2015-11-11 北京元心科技有限公司 容器系统的管理服务方法以及智能终端

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101788926B (zh) * 2009-12-28 2014-04-30 中兴通讯股份有限公司 J2me应用前台切换的资源调配方法及装置
US8375394B2 (en) * 2011-01-18 2013-02-12 Novell, Inc. Techniques to automatically classify processes
TW201241640A (en) * 2011-02-14 2012-10-16 Microsoft Corp Dormant background applications on mobile devices
US8886976B2 (en) * 2011-04-11 2014-11-11 Microsoft Corporation Management of background tasks
US9952897B2 (en) * 2011-09-12 2018-04-24 Microsoft Technology Licensing, Llc Managing processes within suspend states and execution states

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080189708A1 (en) * 2007-02-02 2008-08-07 Ibm Corporation Method and apparatus for preventing undesired termination of a process in an information handling system
CN103443770A (zh) * 2011-03-19 2013-12-11 富士通株式会社 终端装置、进程管理方法以及进程管理程序
CN104252389A (zh) * 2013-06-27 2014-12-31 腾讯科技(深圳)有限公司 应用程序运行方法、系统及应用程序
CN104050035A (zh) * 2014-05-14 2014-09-17 小米科技有限责任公司 应用程序的处理方法及装置
CN105045669A (zh) * 2015-08-26 2015-11-11 北京元心科技有限公司 容器系统的管理服务方法以及智能终端

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3506093A4 *

Also Published As

Publication number Publication date
CN107807847B (zh) 2022-04-29
US20190205160A1 (en) 2019-07-04
EP3506093A4 (en) 2019-09-04
EP3506093A1 (en) 2019-07-03
CN107807847A (zh) 2018-03-16

Similar Documents

Publication Publication Date Title
WO2018045934A1 (zh) 应用进程的管理方法和终端设备
US11099900B2 (en) Memory reclamation method and apparatus
US10187872B2 (en) Electronic device and method of providing notification by electronic device
CN107748686B (zh) 应用程序的启动优化方法、装置、存储介质及智能终端
WO2019206213A1 (zh) 应用程序预加载方法、装置、存储介质及终端
US20200364085A1 (en) Task scheduling based on performance control conditions for multiple processing units
JP6195182B2 (ja) アプリケーションシナリオの識別方法、電力消費の管理方法、装置、および端末デバイス
KR102191971B1 (ko) 모바일 사용자 경험 개선을 위한 가상 머신 마이그레이션 방법 및 이를 위한 장치
WO2018032782A1 (zh) 一种启动应用的方法及装置
WO2018082570A1 (zh) I/o请求的调度方法及装置
EP3358461A1 (en) Apparatus and method for performing application in electronic device
US9983654B2 (en) Electronic device and method of controlling power of electronic device
KR102326945B1 (ko) 태스크 마이그레이션 방법 및 장치
CN110300328B (zh) 一种视频播放控制方法、装置及可读存储介质
WO2019128540A1 (zh) 资源管理方法、移动终端及计算机可读存储介质
WO2018036505A1 (zh) 一种终端后台应用程序的管理方法及装置
KR102586628B1 (ko) 전자 장치 및 전자 장치의 메모리 관리 방법
US9760417B2 (en) Application dehydration and rehydration during application-to-application calls
WO2018072726A1 (zh) 应用启动的管控方法和管控设备
WO2019137252A1 (zh) 内存处理方法、电子设备、计算机可读存储介质
AU2018352618A1 (en) Icon display method, device, and system
US20170131832A1 (en) Input processing method and device
WO2019128537A1 (zh) 应用冻结方法、计算机设备和计算机可读存储介质
WO2017206901A1 (zh) 进程控制方法及相关设备
WO2019128542A1 (zh) 应用处理方法、电子设备、计算机可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17848107

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

ENP Entry into the national phase

Ref document number: 2017848107

Country of ref document: EP

Effective date: 20190326