Linux application process management method and device

文档序号:1963565 发布日期:2021-12-14 浏览:29次 中文

阅读说明:本技术 Linux应用进程管理方法及装置 (Linux application process management method and device ) 是由 王哲 于 2021-11-17 设计创作,主要内容包括:本申请提供一种Linux应用进程管理方法及装置,该方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。(The application provides a method and a device for managing a Linux application process, wherein the method comprises the following steps: acquiring process state change information of a target application; controlling a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process based on the process state change information; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.)

1. A Linux application process management method is characterized by comprising the following steps:

acquiring process state change information of a target application;

controlling the target process to execute the operation corresponding to the state change information through target communication connection established with the target process based on the process state change information;

wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

2. The method of claim 1, wherein prior to obtaining the process state change information of the target application, the method further comprises:

acquiring a starting request of the target application;

creating a target application process in response to the start request;

under the condition that the target application process is successfully established, establishing the target control group, adding the target application process into the target control group, and establishing communication connection with the target application process;

and recording the state information of the target application process based on the current running state of the target application process.

3. The method of claim 2, wherein after recording the state information of the target application process based on the current running state of the target application process, the method further comprises:

acquiring a message of successful creation of a sub-process of the target application process;

establishing communication connection with the subprocess of the target application process;

adding a sub-process of the target application process to the target control group;

and recording the state information of the subprocess of the target application process based on the current running state of the subprocess of the target application process.

4. The method according to any one of claims 1 to 3, wherein the obtaining process state change information of the target application comprises:

acquiring a window focus changing message;

the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps:

controlling the process of acquiring the window focus to enter an activated state, and controlling the process of losing the window focus to enter an inactivated state through the target communication connection under the condition that the process of losing the window focus meets a preset condition;

the process entering the inactive state closes part of the functions, and the process entering the active state re-enables the functions closed when the process enters the inactive state.

5. The method according to any one of claims 1 to 3, wherein the obtaining process state change information of the target application comprises:

acquiring a window hiding message;

the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps:

under the condition that all windows corresponding to a first process are in a hidden state, controlling the first process to enter an invisible running state through the target communication connection;

stopping rendering the window of the first process, and reducing the resource priority of the first process group under the condition that all processes in the first process are in the invisible running state;

wherein the first process is: a process to which the first window belongs; the first window is as follows: the window needing to be hidden is indicated by the window hiding message; the first process group includes: the first process, and/or a sub-process of the first process.

6. The method according to any one of claims 1 to 3, wherein the obtaining process state change information of the target application comprises:

acquiring a suspension message of a second process; the suspend message is used for indicating the second process to enter a suspend state;

the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps:

acquiring window state information of the second process;

under the condition that the window state information indicates that the windows corresponding to the second process are all in a hidden state, sending a first message to the second process through the target communication connection; the first message is used for informing the second process to reserve target data within a first preset time; the target data is necessary data required by the second process during recovery;

after the first preset time is over, sending a SIGINT message to the second process, and controlling the second process to enter a suspended state;

under the condition that all processes in a second process group are in an invisible running state, controlling the processes in the second process group to enter a suspended state;

and the second process group is a process group to which the second process belongs.

7. The method of claim 6, wherein obtaining process state change information for the target application comprises:

acquiring a recovery message of the second process; the recovery message is used for indicating the second process to enter a normal running state from a suspended state;

the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps:

sending a SIGCONT message to the second process;

under the condition that the second process is in a normal running state, sending a second message to the second process through the target communication connection, and controlling the second process to recover the running state of the second process before the second process enters a suspended state based on the target data;

and sending a third message to the window manager, and recovering the window corresponding to the second process.

8. The method according to any one of claims 1 to 3,

the acquiring process state change information of the target application includes: the acquiring process state change information of the target application includes:

acquiring application stop information of a third process;

the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps:

under the condition that the third process is in a suspended state, sending a SIGCONT message to the third process to control the third process to recover the running state;

sending a fourth message to the third process over the target communication connection; the fourth message is used for indicating the third process to complete preparation work before stopping in second preset time;

after the second preset time is finished, sending a SIGTERM message to the third process;

under the condition that the termination of the third process is overtime, sending a SIGKILL message to the third process;

acquiring process state information of a fourth process associated with the third process in the target control group;

and recovering the resources occupied by the fourth process according to a preset recovery strategy based on the process state information of the fourth process.

9. A Linux application process management apparatus, the apparatus comprising:

the acquisition module is used for acquiring process state change information of the target application;

the control module is used for controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information acquired by the acquisition module;

wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

10. A non-transitory computer readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the steps of the Linux application process management method of any of claims 1-8.

Technical Field

The application relates to the field of Linux system software development, in particular to a Linux application process management method and device.

Background

With the development of mobile communication technology, operating systems (e.g., Android, iOS, etc.) on mobile devices have strong life cycle management mechanisms for foreground and background processes of applications based on considerations of power consumption and resource sensitivity of the mobile devices.

However, the Linux operating system for the personal computer does not have the concept of foreground and background, and does not have a corresponding system service framework to support the management of the application process life cycle, so that the Linux application lacks an effective foreground and background process management mechanism.

Disclosure of Invention

The application aims to provide a Linux application process management method and device, which are used for enhancing the background process management of Linux application.

The application provides a Linux application process management method, which comprises the following steps:

acquiring process state change information of a target application; controlling a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process based on the process state change information; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

Optionally, before the obtaining of the process state change information of the target application, the method further includes: acquiring a starting request of the target application; creating a target application process in response to the start request; under the condition that the target application process is successfully established, establishing the target control group, adding the target application process into the target control group, and establishing communication connection with the target application process; and recording the state information of the target application process based on the current running state of the target application process.

Optionally, after recording the state information of the target application process based on the current running state of the target application process, the method further includes: acquiring a message of successful creation of a sub-process of the target application process; establishing communication connection with the subprocess of the target application process; adding a sub-process of the target application process to the target control group; and recording the state information of the subprocess of the target application process based on the current running state of the subprocess of the target application process.

Optionally, the obtaining process state change information of the target application includes: acquiring a window focus changing message; the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps: controlling the process of acquiring the window focus to enter an activated state, and controlling the process of losing the window focus to enter an inactivated state through the target communication connection under the condition that the process of losing the window focus meets a preset condition; the process entering the inactive state closes part of the functions, and the process entering the active state re-enables the functions closed when the process enters the inactive state.

Optionally, the obtaining process state change information of the target application includes: acquiring a window hiding message; the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps: under the condition that all windows corresponding to a first process are in a hidden state, controlling the first process to enter an invisible running state through the target communication connection; stopping rendering the window of the first process, and reducing the resource priority of the first process group under the condition that all processes in the first process are in the invisible running state; wherein the first process is: a process to which the first window belongs; the first window is as follows: the window needing to be hidden is indicated by the window hiding message; the first process group includes: the first process, and/or a sub-process of the first process.

Optionally, the obtaining process state change information of the target application includes: acquiring a suspension message of a second process; the suspend message is used for indicating the second process to enter a suspend state; the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps: acquiring window state information of the second process; under the condition that the window state information indicates that the windows corresponding to the second process are all in a hidden state, sending a first message to the second process through the target communication connection; the first message is used for informing the second process to reserve target data within a first preset time; the target data is necessary data required by the second process during recovery; after the first preset time is over, sending a SIGINT message to the second process, and controlling the second process to enter a suspended state; under the condition that all processes in a second process group are in an invisible running state, controlling the processes in the second process group to enter a suspended state; and the second process group is a process group to which the second process belongs.

Optionally, the obtaining process state change information of the target application includes: acquiring a recovery message of the second process; the recovery message is used for indicating the second process to enter a normal running state from a suspended state; the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps: sending a SIGCONT message to the second process; under the condition that the second process is in a normal running state, sending a second message to the second process through the target communication connection, and controlling the second process to recover the running state of the second process before the second process enters a suspended state based on the target data; and sending a third message to the window manager, and recovering the window corresponding to the second process.

Optionally, the obtaining process state change information of the target application includes: the acquiring process state change information of the target application includes: acquiring application stop information of a third process; the controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information comprises the following steps: under the condition that the third process is in a suspended state, sending a SIGCONT message to the third process to control the third process to recover the running state; sending a fourth message to the third process over the target communication connection; the fourth message is used for indicating the third process to complete preparation work before stopping in second preset time; after the second preset time is finished, sending a SIGTERM message to the third process; sending a SIGKILL message to the third process through the target communication connection under the condition that the termination of the third process is overtime; acquiring process state information of a fourth process associated with the third process in the target control group; and recovering the resources occupied by the fourth process according to a preset recovery strategy based on the process state information of the fourth process.

The present application further provides a Linux application process management device, including:

the acquisition module is used for acquiring process state change information of the target application; the control module is used for controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information acquired by the acquisition module; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

Optionally, the apparatus further comprises: the device comprises a group management module, a communication module and a recording module; the obtaining module is further configured to obtain a start request of the target application; the group management module is used for responding to the starting request acquired by the acquisition module and establishing a target application process; the group management module is further configured to create the target control group and add the target application process to the target control group when the creation of the target application process is successful; the communication module is used for establishing communication connection with the target application process; and the recording module is used for recording the state information of the target application process based on the current running state of the target application process.

Optionally, the obtaining module is further configured to obtain a message that the creation of the sub-process of the target application process is successful; the communication module is also used for establishing communication connection with the subprocess of the target application process; the group management module is used for adding the sub-process of the target application process into the target control group; the recording module is further configured to record state information of the subprocess of the target application process based on the current running state of the subprocess of the target application process.

Optionally, the obtaining module is specifically configured to obtain a window focus changing message; the control module is specifically used for controlling the process of acquiring the window focus to enter an activation state; the control module is further configured to control the process losing the window focus to enter an inactive state through the target communication connection when the process losing the window focus meets a preset condition; the process entering the inactive state closes part of the functions, and the process entering the active state re-enables the functions closed when the process enters the inactive state.

Optionally, the apparatus further comprises a display module and a resource management module; the acquisition module is specifically used for acquiring a window hiding message; the control module is specifically configured to, when all windows corresponding to a first process are in a hidden state, control the first process to enter an invisible operating state through the target communication connection; the display module is used for stopping rendering the window of the first process; the resource management module is used for reducing the resource priority of the first process group under the condition that all processes in the first process are in the invisible running state; wherein the first process is: a process to which the first window belongs; the first window is as follows: the window needing to be hidden is indicated by the window hiding message; the first process group includes: the first process, and/or a sub-process of the first process.

Optionally, the obtaining module is specifically configured to obtain a suspension message of the second process; the obtaining module is further configured to obtain window state information of the second process; the control module is specifically configured to send a first message to the second process through the target communication connection when the window state information indicates that the windows corresponding to the second process are all in a hidden state; the first message is used for informing the second process to reserve target data within a first preset time; the target data is necessary data required by the second process during recovery; the communication module is specifically configured to send a SIGINT message to the second process after the first preset time is ended; the control module is specifically configured to control the second process to enter a suspended state; the control module is specifically configured to control the processes in the second process group to enter a suspended state when all the processes in the second process group are in an invisible running state; and the second process group is a process group to which the second process belongs.

Optionally, the obtaining module is specifically configured to obtain a recovery message of the second process; the recovery message is used for indicating the second process to enter a normal running state from a suspended state; the communication module is further configured to send a sigscot message to the second process; the communication module is further configured to send a second message to the second process through the target communication connection when the second process is in a normal operating state; the control module is specifically configured to control the second process to resume, based on the target data, an operating state of the second process before the second process enters the suspended state; the communication module is further configured to send a third message to the window manager, and recover the window corresponding to the second process.

Optionally, the obtaining module is specifically configured to obtain application stop information of a third process; the communication module is further configured to send a sigscot message to the third process when the third process is in a suspended state; the control module is specifically configured to control the third process to recover the running state; the communication module is further configured to send a fourth message to the third process through the target communication connection; the fourth message is used for indicating the third process to complete preparation work before stopping in second preset time; the communication module is further configured to send a SIGTERM message to the third process after the second preset time is ended; the communication module is further configured to send a SIGKILL message to the third process when the third process is terminated and timed out; the obtaining module is further configured to obtain process state information of a fourth process associated with the third process in the target control group; and the resource management module is further configured to recycle, based on the process state information of the fourth process, the resource occupied by the fourth process according to a preset recycling strategy.

The present application further provides a computer program product comprising computer programs/instructions which, when executed by a processor, implement the steps of the Linux application process management method as any one of the above.

The application also provides an electronic device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor executes the program to realize the steps of the Linux application process management method.

The present application further provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the Linux application process management method as any one of the above.

According to the Linux application process management method and device, the process information of each process in the target control group is obtained through the target control group of the target application, and communication connection is established between the process information and the target control group. And then, when the system acquires the process state change information of the target application in the target control group, based on the process state change information, sending a control message to the target process through the target communication connection established with the target process, and controlling the target process to execute the operation corresponding to the state change information, thereby realizing the management of the whole life cycle of each process of the target application.

Drawings

In order to more clearly illustrate the technical solutions in the present application or the prior art, the drawings needed for the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.

FIG. 1 is a schematic flow chart of a Linux application process management method provided in the present application;

FIG. 2 is a schematic diagram illustrating a start-up process of a main process of a Linux application provided in the present application;

FIG. 3 is a schematic diagram illustrating a sub-process starting flow of the Linux application provided in the present application;

FIG. 4 is a schematic flow chart illustrating an application process management service controlling process entering an inactive running state according to the present application;

FIG. 5 is a flow chart illustrating an application process management service controlling a process entering an invisible running state provided by the present application;

FIG. 6 is a flow chart illustrating an application process management service controlling a process entering a suspend state according to the present application;

FIG. 7 is a flow diagram illustrating a recovery process from a suspended state by an application process management service control process provided herein;

FIG. 8 is a flow diagram illustrating the termination of an application process management service control process provided herein;

FIG. 9 is a schematic structural diagram of a Linux application process management device provided in the present application;

fig. 10 is a schematic structural diagram of an electronic device provided in the present application.

Detailed Description

To make the purpose, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be clearly and completely described below with reference to the drawings in the present application, and it is obvious that the described embodiments are some, but not all embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.

The terms first, second and the like in the description and in the claims of the present application are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that embodiments of the application may be practiced in sequences other than those illustrated or described herein, and that the terms "first," "second," and the like are generally used herein in a generic sense and do not limit the number of terms, e.g., the first term can be one or more than one. In addition, "and/or" in the specification and claims means at least one of connected objects, a character "/" generally means that a preceding and succeeding related objects are in an "or" relationship.

Mobile operating systems (e.g., Android, iOS, etc.) have strong mechanisms for managing application lifecycle due to their sensitivity to hardware resources and power consumption. For example, foreground applications are active, background applications are suspended; and when the system resources are in shortage, recycling part of the application to release the resources. The traditional Linux operating system is mainly developed for a personal computer, has no foreground and background concepts in application, and has almost no operation limitation on the application, so that the power consumption performance on mobile equipment is poor. In addition, when a general Linux operating system starts an application, the application is started by simply creating a process through a fork function, and the subsequent self-created child processes and grandchild processes of the application are not monitored, so that the operations of suspending and recovering the associated processes are not easily completed.

The application is started by a unified starter, the basic foreground and background life cycle capability is provided by matching with a window manager, an independent process management group is established for each application by matching with a cgroup mechanism of the Linux, all descendant processes related to the application can be managed, the control of suspension, recovery and the like of all application related processes is realized, the management of the Linux application life cycle is enhanced, the energy consumption is reduced, the operating efficiency of a system is improved, and the requirement on the hardware performance of equipment is reduced.

The Linux application process management method provided by the embodiment of the present application is described in detail below with reference to the accompanying drawings through specific embodiments and application scenarios thereof.

As shown in fig. 1, a Linux application process management method provided in an embodiment of the present application may include the following steps 101 and 102:

step 101, acquiring process state change information of a target application.

In an exemplary embodiment, in the Linux application process management method provided in this embodiment, based on the cooperation between the system-level application process management service and the application end component, based on the application end component, the application process management service may establish a communication connection with an application process, thereby implementing the application process management service to perform an all-around control on the application process. Namely, the execution main body of the Linux application process management method provided by the embodiment of the application can serve the application process management.

For example, the application end component may be a library, which is used for implementing communication with the application process management service after the application end is integrated. That is, if the Linux application wants to implement communication with the application process management service, the application side component must be integrated.

For example, the process state change information of the target application may be acquired by the application process management service, and based on the process state change information, a control instruction corresponding to the process state change information is sent to the Linux application process, so as to implement control and management of the Linux process.

Illustratively, the process state change information may include at least one of: creating a sub-process, enabling the process to enter an inactive state, enabling the process to enter an active state, hiding the process, suspending the process, recovering the process, terminating the process and the like. It can be understood that the inactive state of the process indicates that the process is running, but the window corresponding to the process does not have the user focus; the activation state of the process indicates that the process is running and the window corresponding to the process has a user focus; the hidden process indicates that the process is running, but the window corresponding to the process is hidden.

For example, the process state change information of the target application may be actively acquired by the application process management service, or may be sent to the application process management service by another system service, for example, the window manager may send a window hiding message to the application process management service.

And 102, controlling the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process based on the process state change information.

Wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

It can be understood that, based on the target communication connection established between the application process management service and the application process, the application process management service may send control information to the corresponding process through the target communication connection based on the process state change information after acquiring the process state change information of the application process, and the application end component executes an operation corresponding to the control information after receiving the control information, thereby controlling the process.

For example, after the Linux application is created, all child processes and grandchild processes created based on the main process of the application are included in the same control group (cgroup), i.e., the target control group. The application process management service can monitor each process in the target control group through the control group, and acquire the process associated with each process, the hierarchical relationship among the processes and the like.

Illustratively, after acquiring the process state change information, the application process management service sends a corresponding control instruction to the Linux application process indicated by the process state change information through the target communication connection based on the process state change information, and controls the Linux process to execute a corresponding action, thereby realizing management of the Linux application process from creation to termination of the whole life cycle by the application process management service.

Therefore, the process information of each process in the target control group is obtained through the target control group of the target application, and communication connection is established with the process information. And then, when the system acquires the process state change information of the target application in the target control group, based on the process state change information, sending a control message to the target process through the target communication connection established with the target process, and controlling the target process to execute the operation corresponding to the state change information, thereby realizing the management of the whole life cycle of each process of the target application.

Optionally, in this embodiment of the present application, if it is desired to implement lifecycle management on a Linux application process, a control group for all processes of the Linux application is created based on the Linux application.

For example, before the step 101, the method for managing a Linux application process according to the embodiment of the present application may further include the following steps 103 to 106:

and step 103, acquiring a starting request of the target application.

And 104, responding to the starting request, and creating a target application process.

For example, the target application process is a host process of the target application, and after the host process of the target application is created, the target control group can be created, and other processes created subsequently are also added to the target control group.

And 105, under the condition that the target application process is successfully established, establishing the target control group, adding the target application process into the target control group, and establishing communication connection with the target application process.

And 106, recording the state information of the target application process based on the current running state of the target application process.

For example, after the target application process is successfully created, the application process management service needs to record a process identification (pid) of the target application process and a current running state of the target application process, so as to facilitate subsequent management of the process and obtain or update the current running state of the process.

For example, after the target application is started, the application process management service may further obtain an Identity (ID) of a window created by the target application process from the window manager, and record the target application process and state information of the window. That is, the state information of the target application process may further include window state information of a window corresponding to the target application process.

For example, as shown in fig. 2, a flowchart of the Linux application main process starting process is shown. After acquiring a program starting request of the Linux application, the application process management service creates a main process (i.e., the target application process) of the Linux application through a fork function. And after the main process is successfully created, feeding back a successful creation result to the application process management service, and returning the PID of the main process. Then, the application process management service establishes a control group (i.e. the target control group) for the target application based on the host process, and adds the PID of the host process to the management task of the application process management service. For the Linux application, after the main process is successfully established, the normal starting process of the application is continuously executed, and the Linux application is started.

After the Linux application starting process is completed, the main process establishes communication connection with the application process management service, and the application process management service sends a successful establishment message to the main process after successfully establishing communication connection with the main process. The application process management service may send control instructions to the host process via a communication connection established with the host process.

After the main process starting process is completed, the main process submits a window display request to a Linux window manager, and after the window manager receives the request, the window of the main process is used as a current window for rendering and synthesizing, and is set as a focus window.

Further optionally, in this embodiment of the application, after the main process of the Linux application is successfully created, for the sub-process created on the basis of the main process, the process management service also needs to establish a communication connection with the sub-process, and record the current state of the sub-process.

After the step 106, the method for managing a Linux application process according to the embodiment of the present application may further include the following steps 107 to 110:

and step 107, acquiring a message that the creation of the sub-process of the target application process is successful.

And step 108, establishing communication connection with the subprocess of the target application process.

And step 109, adding the sub-process of the target application process into the target control group.

Step 110, recording the state information of the subprocess of the target application process based on the current running state of the subprocess of the target application process.

Illustratively, similar to the creating process of the main process of the Linux application, the application process management service establishes a communication connection with a sub-process of the Linux application after the sub-process is successfully created, and feeds back a result to the sub-process after the communication connection is successfully established.

It can be understood that the application process management service needs to communicate with the processes of the Linux application, and needs to establish a communication connection with each process of the Linux application.

For example, as shown in fig. 3, a flowchart of starting a sub-process of a Linux application is shown. When the Linux application main process needs to create a sub-process, the Linux application main process needs to request the Linux kernel to create the sub-process, and specifically, the sub-process is created through a fork function. After the Linux kernel creates the child process, the child process is added to the process group of the parent process (namely the main process) through the control group cgroup created when the main process is started. The process and the descendant process of the process are added into the process group of the process, so that the process associated with the process is conveniently acquired.

After the Linux kernel successfully creates the subprocess, the subprocess executes a specific starting process, and then communication connection between the Linux kernel and the application process management service is created.

Therefore, the application process management service can establish communication connection with all the processes established by the Linux application through the method, and each process of the Linux application can be managed conveniently through the communication connection.

Optionally, in this embodiment of the application, based on the created target control group, the application process management service may implement management of the whole life cycle of each process through a communication connection established with each process in the target control group.

Illustratively, based on different states of a process, the following example provided in the embodiments of the present application specifically describes how to implement management of a process by applying a process management service.

Example 1:

in example 1, if it is desired to control a process in the target control group to enter an inactive state, control may be performed according to the following control flow.

Exemplarily, the step 101 may include the following steps 101 a:

and step 101a, acquiring a window focus changing message.

Illustratively, the window focus change message is obtained by the application process management service from a Linux window manager.

Illustratively, the step 102 may include the following steps 102 a:

and 102a, controlling the process of obtaining the window focus to enter an activated state, and controlling the process of losing the window focus to enter an inactivated state through the target communication connection under the condition that the process of losing the window focus meets a preset condition.

The process entering the inactive state closes part of the functions, and the process entering the active state re-enables the functions closed when the process enters the inactive state.

For example, unlike directly controlling the window focus change of a process through a Linux control instruction, the application process management service may first determine whether the process losing the window focus satisfies a preset condition, for example, whether the process losing the window focus still has a displayed window. And controlling the process losing the window focus to enter an inactive running state under the condition of meeting a preset condition.

For example, as shown in fig. 4, a flowchart for controlling a process to enter an inactive operation state for an application process management service is shown. After the application process management service acquires the window focus change message sent by the Linux window manager, the application process management service calculates process state changes according to the focus window and the states of all process groups, namely which processes enter an activated running state and which processes enter an inactivated running state.

And for the process which obtains the focus, the related functions are reactivated and enter an activated running state, and for the process which loses the focus, the related functions are paused and enter an inactivated running state.

Example 2:

in example 2, if it is desired to control a process in the target control group to enter an invisible operating state, control may be performed according to the following control flow.

Illustratively, the step 101 may include the following steps 101 b:

and step 101b, acquiring a window hiding message.

Illustratively, the window hiding message is used to control the window corresponding to the process to enter a hidden state.

Illustratively, the step 102 may include the following steps 102b1 and 102b 2:

step 102b1, controlling the first process to enter the invisible running state through the target communication connection under the condition that all windows corresponding to the first process are in the hidden state.

Step 102b2, stopping rendering the window of the first process, and reducing the resource priority of the first process group under the condition that all processes in the first process are in the invisible running state.

Wherein the first process is: a process to which the first window belongs; the first window is as follows: the window needing to be hidden is indicated by the window hiding message; the first process group includes: the first process, and/or a sub-process of the first process.

Illustratively, the first process is the target process in step 101. The first process and the sub-processes of the first process form a first process group.

For example, as shown in fig. 5, a flowchart for controlling a process to enter an invisible running state for an application process management service is shown. After acquiring the window hiding message sent by the Linux window manager, the application process management service calculates the process state change according to the hidden window and the states of each process group, and meanwhile, the Linux window manager releases the surface resource corresponding to the window to be hidden.

And if all windows of the process to which the window to be hidden belongs are hidden and invisible, the process enters an invisible running state. Thereafter, rendering of the process-related window content is stopped. And when all the processes in the process group of the process are in the invisible running state, the resource priority of the process group is properly reduced.

Example 3:

in example 3, if it is desired to control a process in the target control group to enter the suspended state, control may be performed according to the following control flow.

Illustratively, the step 101 may include the following steps 101 c:

and step 101c, acquiring a suspension message of the second process.

Wherein the suspend message is used to indicate that the second process enters a suspended state.

Illustratively, the second process is the target process in step 101.

Illustratively, the step 102 may include the following steps 102c1 to 102c 3:

and step 101c1, acquiring the window state information of the second process.

Illustratively, the window state information is used to indicate current states of all windows corresponding to the second process.

Step 101c2, sending a first message to the second process through the target communication connection when the window state information indicates that the windows corresponding to the second process are all in a hidden state.

The first message is used for informing the second process to reserve target data within a first preset time; the target data is necessary data required by the second process when recovering.

Illustratively, the first predetermined time is a time for retaining necessary data required for a reply before the second process suspends. The application process management service firstly informs the second process that the second process is to be suspended after the first preset time, and the second process completes the data storage within the first preset time after receiving the notification, so that the current running state can be conveniently recovered when the process is recovered later.

And step 101c3, after the first preset time is over, sending a SIGINT message to the second process, and controlling the second process to enter a suspended state.

For example, if the second process corresponds to a plurality of windows, the state of each window needs to be considered. And controlling the second process to enter a suspended state under the condition that the windows corresponding to the second process are all in a hidden state.

And step 101c4, under the condition that all processes in the second process group are in the invisible running state, controlling the processes in the second process group to enter a suspended state.

And the second process group is a process group to which the second process belongs.

Illustratively, based on the above steps, after the process enters the suspended state, the occupation of the system resources by the process is reduced.

For example, as shown in fig. 6, a flowchart for controlling a process to enter a suspended state for an application process management service is shown. After acquiring a message that a certain process needs to be suspended, the application process manager sends a suspension message to the suspended process, where the suspension message is used to instruct the suspended process to reserve necessary data required for recovery within a suspension preparation time (i.e., the first preset time), so that the process can be recovered to a state before suspension when the process is recovered.

And then, after the suspension preparation time is over, the application process manager sends a SIGINT message to the suspended process, and the Linux kernel controls the process to enter a suspended state. Finally, the application process management service marks the suspended process as a suspended state.

Example 4:

in example 4, based on the above example 3, if it is desired that a process in the control-target control group be resumed from the suspended state, control can be performed according to the following control flow.

Illustratively, the step 101 may include the following steps 101 d:

and step 101d, acquiring the recovery message of the second process.

Wherein the resume message is used to instruct the second process to enter a normal running state from a suspended state.

Illustratively, the step 102 may include the following steps 102d1 to 102d 3:

step 102d1, sending a SIGCONT message to the second process over the target communication connection.

For example, when the application process management service wants to recover the suspended second process, it can send a sigscot message directly to the second process.

Step 102d2, when the second process is in a normal operation state, sending a second message to the second process through the target communication connection, and controlling the second process to resume the operation state of the second process before entering the suspended state based on the target data.

Illustratively, after the second process is resumed from the suspended state, the application process management service sends a process resume notification to the second process, controlling the second process to resume the running state based on data that was retained by the second process while the process was suspended.

And step 102d3, sending a third message to the window manager, and recovering the window corresponding to the second process.

Illustratively, after the data and the state of the second process are restored, the application process management service re-pulls up the window corresponding to the second process through the window manager.

For example, as shown in fig. 7, a flowchart for controlling the process recovery from the suspended state for the application process management service is shown. If the application process manager wants to restore a certain process from the suspended state to the normal running state, a SIGINT message can be sent to the restored process, and the Linux kernel restores the running of the process. And then, the application process management service informs the recovered process of recovering the data and the state, and the recovered process carries out data recovery and state recovery based on the data reserved during suspension. And finally, applying the process management service to re-pull the window corresponding to the recovered process in a mode of sending an instruction to the window manager.

Example 5:

in example 5, if it is desired to terminate a process in the control target control group, control may be performed according to the following control flow.

Illustratively, the step 101 may include the following steps 101 e:

and step 101e, acquiring application stop information of the third process.

Illustratively, the step 102 may include the following steps 102e1 to 102e 6:

step 102e1, sending sigcontrol message to the third process to control the third process to resume running state if the third process is in suspended state.

For example, when the application process management service terminates the third process, it needs to determine whether the third process is in a suspended state, and if the third process is in the suspended state, there may be some data that is not saved when the third process is terminated, and therefore, the third process needs to be resumed from the suspended state.

Step 102e2, sending a fourth message to the third process over the target communication connection.

The fourth message is used for indicating that the third process completes preparation work before stopping in a second preset time.

Illustratively, in a case that the third process is in a normal operating state, the application process management service sends the fourth message to the third process, indicating that the third process has saved the unsaved data within a second preset time.

And step 102e3, sending a SIGTERM message to the third process after the second preset time is over.

Illustratively, after the second preset time is over, the application process management service sends SIGTERM to the third process again, and terminates the third process.

Step 102e4, sending a SIGKILL message to the third process in case the third process expires.

Illustratively, the SIGINT cancel, sigcnt message, sigtherm message, and SIGKILL message are Linux process control signals, which can be sent to a designated process through a Linux kernel.

For example, if the termination of the third process is timed out, the application process management service may also send a SIGKILL message to the third process to forcibly terminate the third process.

Step 102e5, obtaining process state information of a fourth process within the target control group associated with the third process.

And 102e6, recovering the resource occupied by the fourth process according to a preset recovery strategy based on the process state information of the fourth process.

Illustratively, after a process terminates, the application process management service also needs to perform resource reclamation on the terminated process. Specifically, for the third process, the descendant process created based on the third process, and the like, after the third process is terminated, it may be determined whether the fourth process has a window or the like being displayed, and whether to recycle the resource occupied by the fourth process may be determined.

For example, as shown in fig. 8, a flow diagram for controlling the termination of a process for application process management service is shown. The application process management service firstly judges whether the terminated process is in a suspended state, if so, a SIGCONT message is sent to the terminated process, and the Linux kernel resumes the operation of the suspended process. Then, the application management service sends a notification to the terminated process, notifying that the process is about to be terminated after a certain time (i.e., the second preset time), and after receiving the notification, the terminated process performs preparation before termination, and saves necessary data.

And after the time is over, the application process management service sends a SIGTERM message to the terminated process, and the Linux kernel terminates the process. If the process is terminated and overtime, a SIGKILL message is sent to the process, and the process is forcibly terminated. And then, calculating the process state of the associated process of the terminated process according to the cgroup, and recovering the process resources according to a preset resource recovery strategy.

Thus, the application process management service can manage the whole life cycle of each process of the Linux application according to the process management method.

According to the Linux application process management method provided by the embodiment of the application, the process information of each process in the target control group is acquired through the target control group of the target application, and the communication connection is established between the process information and the target control group. And then, when the system acquires the process state change information of the target application in the target control group, based on the process state change information, sending a control message to the target process through the target communication connection established with the target process, and controlling the target process to execute the operation corresponding to the state change information, thereby realizing the management of the whole life cycle of each process of the target application.

It should be noted that, in the Linux application process management method provided in the embodiment of the present application, the execution main body may be a Linux application process management device, or a control module in the Linux application process management device for executing the Linux application process management method. The Linux application process management device provided by the embodiment of the application is described by taking the Linux application process management device as an example to execute the Linux application process management method.

In the embodiments of the present application, the above-described methods are illustrated in the drawings. The Linux application process management method is exemplarily described by referring to one of the drawings in the embodiments of the present application. In specific implementation, the Linux application process management method shown in each method drawing can also be implemented by combining any other drawing which can be combined and is illustrated in the above embodiments, and details are not described here again.

The following description is provided for the present application, and the following description and the Linux application process management method described above may be referred to correspondingly.

Fig. 9 is a schematic structural diagram of a Linux application process management device according to an embodiment of the present application, as shown in fig. 9, specifically including:

an obtaining module 901, configured to obtain process state change information of a target application; a control module 902, configured to control, based on the process state change information acquired by the acquisition module 901, a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

Optionally, the apparatus further comprises: the device comprises a group management module, a communication module and a recording module; the obtaining module 901 is further configured to obtain a start request of the target application; a group management module, configured to create a target application process in response to the start request acquired by the acquisition module 901; the group management module is further configured to create the target control group and add the target application process to the target control group when the creation of the target application process is successful; the communication module is used for establishing communication connection with the target application process; and the recording module is used for recording the state information of the target application process based on the current running state of the target application process.

Optionally, the obtaining module 901 is further configured to obtain a message that the creation of the sub-process of the target application process is successful; the communication module is also used for establishing communication connection with the subprocess of the target application process; the group management module is used for adding the sub-process of the target application process into the target control group; the recording module is further configured to record state information of the subprocess of the target application process based on the current running state of the subprocess of the target application process.

Optionally, the obtaining module 901 is specifically configured to obtain a window focus changing message; the control module 902 is specifically configured to control a process of acquiring a window focus to enter an active state; the control module 902 is further configured to, when the process that loses the window focus meets a preset condition, control the process that loses the window focus to enter an inactive state through the target communication connection; the process entering the inactive state closes part of the functions, and the process entering the active state re-enables the functions closed when the process enters the inactive state.

Optionally, the apparatus further comprises a display module and a resource management module; the obtaining module 901 is specifically configured to obtain a window hiding message; the control module 902 is specifically configured to, when all windows corresponding to a first process are in a hidden state, control the first process to enter an invisible running state through the target communication connection; the display module is used for stopping rendering the window of the first process; the resource management module is used for reducing the resource priority of the first process group under the condition that all processes in the first process are in the invisible running state; wherein the first process is: a process to which the first window belongs; the first window is as follows: the window needing to be hidden is indicated by the window hiding message; the first process group includes: the first process, and/or a sub-process of the first process.

Optionally, the obtaining module 901 is specifically configured to obtain a suspension message of the second process; the obtaining module 901 is further configured to obtain window state information of the second process; the control module 902 is specifically configured to send a first message to the second process through the target communication connection when the window state information indicates that the windows corresponding to the second process are all in a hidden state; the first message is used for informing the second process to reserve target data within a first preset time; the target data is necessary data required by the second process during recovery; the communication module is specifically configured to send, after the first preset time is ended, a SIGINT message to the second process through the target communication connection; the control module 902 is specifically configured to control the second process to enter a suspended state; the control module 902 is specifically configured to, when all processes in the second process group are in the invisible running state, control the processes in the second process group to enter the suspended state; and the second process group is a process group to which the second process belongs.

Optionally, the obtaining module 901 is specifically configured to obtain a recovery message of the second process; the recovery message is used for indicating the second process to enter a normal running state from a suspended state; the communication module is further configured to send a sigscot message to the second process; the communication module is further configured to send a second message to the second process through the target communication connection when the second process is in a normal operating state; the control module 902 is specifically configured to control the second process to resume, based on the target data, an operating state of the second process before entering the suspended state; the communication module is further configured to send a third message to the window manager, and recover the window corresponding to the second process.

Optionally, the obtaining module 901 is specifically configured to obtain application stop information of a third process; the communication module is further configured to send a sigscot message to the third process when the third process is in a suspended state; the control module 902 is specifically configured to control the third process to resume the running state; the communication module is further configured to send a fourth message to the third process through the target communication connection; the fourth message is used for indicating the third process to complete preparation work before stopping in second preset time; the communication module is further configured to send a SIGTERM message to the third process after the second preset time is ended; the communication module is further configured to send a SIGKILL message to the third process when the third process is terminated and timed out; the obtaining module 901 is further configured to obtain process state information of a fourth process associated with the third process in the target control group; and the resource management module is further configured to recycle, based on the process state information of the fourth process, the resource occupied by the fourth process according to a preset recycling strategy.

According to the Linux application process management device, the process information of each process in the target control group is acquired through the target control group of the target application, and communication connection is established between the process information and the target control group. And then, when the system acquires the process state change information of the target application in the target control group, based on the process state change information, sending a control message to the target process through the target communication connection established with the target process, and controlling the target process to execute the operation corresponding to the state change information, thereby realizing the management of the whole life cycle of each process of the target application.

Fig. 10 illustrates a physical structure diagram of an electronic device, and as shown in fig. 10, the electronic device may include: a processor (processor)1010, a communication Interface (Communications Interface)1020, a memory (memory)1030, and a communication bus 1040, wherein the processor 1010, the communication Interface 1020, and the memory 1030 communicate with each other via the communication bus 1040. The processor 1010 may call logic instructions in the memory 1030 to perform a Linux application process management method comprising: acquiring process state change information of a target application; controlling a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process based on the process state change information; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

Furthermore, the logic instructions in the memory 1030 can be implemented in software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.

In another aspect, the present application further provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, when the program instructions are executed by a computer, the computer being capable of executing the Linux application process management method provided by the above methods, the method comprising: acquiring process state change information of a target application; controlling a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process based on the process state change information; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

In yet another aspect, the present application further provides a non-transitory computer readable storage medium having stored thereon a computer program, which when executed by a processor is implemented to perform the Linux application process management method provided in the above aspects, the method comprising: acquiring process state change information of a target application; controlling a target process to execute an operation corresponding to the state change information through a target communication connection established with the target process based on the process state change information; wherein the target process is a process in a target control group of the target application; the target communication connection is a communication connection established with the target process when the target process is established.

The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.

Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.

Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

25页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种基于多级轮询队列控制器部署学习模型的方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!