WO2023087765A1 - Linux应用进程管理方法及装置 - Google Patents

Linux应用进程管理方法及装置 Download PDF

Info

Publication number
WO2023087765A1
WO2023087765A1 PCT/CN2022/107182 CN2022107182W WO2023087765A1 WO 2023087765 A1 WO2023087765 A1 WO 2023087765A1 CN 2022107182 W CN2022107182 W CN 2022107182W WO 2023087765 A1 WO2023087765 A1 WO 2023087765A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
state
application
message
change information
Prior art date
Application number
PCT/CN2022/107182
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 北京字节跳动网络技术有限公司
Publication of WO2023087765A1 publication Critical patent/WO2023087765A1/zh

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/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/485Task life-cycle, e.g. stopping, restarting, resuming execution

Definitions

  • the present disclosure relates to the field of Linux system software development, in particular to a Linux application process management method and device.
  • operating systems eg, Android, iOS, etc.
  • mobile devices have a strong life cycle management mechanism for front and back processes of applications based on the consideration of power consumption and resource sensitivity of mobile devices.
  • the Linux operating system for personal computers does not have the concept of front-end and back-end, and there is no corresponding system service framework to support the management of the application process life cycle, resulting in the lack of an effective front-end and back-end process management mechanism for Linux applications.
  • the purpose of the present disclosure is to provide a Linux application process management method and device for enhancing front and back process management of Linux applications.
  • the present disclosure provides a Linux application process management method, including:
  • the method before acquiring the process state change information of the target application, the method further includes: acquiring a start request of the target application; in response to the start request, creating a target application process; If successful, create the target control group, add the target application process to the target control group, and establish a communication connection with the target application process; based on the current running state of the target application process, Record the status information of the target application process.
  • the method further includes: obtaining a message that the child process of the target application process is created successfully; A communication connection between subprocesses of the target application process; adding the subprocesses of the target application process to the target control group; recording the target application process based on the current running status of the subprocesses of the target application process Status information of the child process.
  • the acquiring the process state change information of the target application includes: acquiring a window focus change message; based on the process state change information, controlling the execution of the target process through the target communication connection established with the target process
  • the operation corresponding to the state change information includes: controlling the process that acquires the window focus to enter an active state, and when the process that loses the window focus satisfies a preset condition, controls the process that loses the window focus to The process enters the inactive state; wherein, the process entering the inactive state will close some functions, and the process entering the active state will re-enable the functions that were closed when the process entered the inactive state.
  • the acquiring process status change information of the target application includes: acquiring a window hidden message; based on the process status change information, controlling the execution of the target process and the target application through a target communication connection established with the target process
  • the operation corresponding to the state change information includes: when all the windows corresponding to the first process are in a hidden state, control the first process to enter an invisible running state through the target communication connection; stop rendering the first process A window of a process, and when all processes in the first process are in an invisible running state, reduce the resource priority of the first process group; wherein, the first process is: the process to which the first window belongs ;
  • the first window is: the window that needs to be hidden indicated by the window hiding message;
  • the first process group includes: the first process, and/or, a child process of the first process.
  • the obtaining the process state change information of the target application includes: obtaining a suspension message of the second process; the suspension message is used to indicate that the second process enters a suspension state;
  • the state change information controls the target process to execute the operation corresponding to the state change information, including: obtaining the window state information of the second process; indicating in the window state information
  • send a first message to the second process through the target communication connection the first message is used to notify the second process Retaining target data within a preset time; the target data is necessary data required for recovery of the second process; when the first preset time is over, send a SIGINT message to the second process to control the
  • the second process enters the suspended state; when all the 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; wherein, the second process group is the process group to which the second process belongs.
  • the obtaining process state change information of the target application includes: obtaining a recovery message of the second process; the recovery message is used to indicate that the second process enters a normal running state from a suspended state; the Based on the process state change information, controlling the target process to perform an operation corresponding to the state change information through the target communication connection established with the target process, including: sending a SIGCONT message to the second process; When the second process is in a normal running state, send a second message to the second process through the target communication connection, and control the second process to resume before the second process enters the suspended state based on the target data the running state of the process; sending a third message to the window manager to restore the window corresponding to the second process.
  • the obtaining the process state change information of the target application includes: the obtaining the process state change information of the target application includes: obtaining the application stop information of the third process; based on the process state change information, by A target communication connection established with the target process, controlling the target process to perform operations corresponding to the state change information, including: sending a SIGCONT message to the third process when the third process is in a suspended state , controlling the third process to resume the running state; sending a fourth message to the third process through the target communication connection; the fourth message is used to indicate that the third process is completed within a second preset time Preparatory work before stopping; when the second preset time is over, send a SIGTERM message to the third process; when the third process terminates overtime, send a message to the third process through the target communication connection
  • the process sends a SIGKILL message; acquires process status information of a fourth process associated with the third process in the target control group; based on the process status information of the fourth process, recovers the fourth process according to a preset recovery
  • the present disclosure also provides a Linux application process management device, including:
  • An acquisition module configured to acquire process state change information of the target application
  • a control module configured to control the execution of the target process to communicate with the target application through a target communication connection established with the target process based on the process state change information acquired by the acquisition module.
  • An operation corresponding to the state change information wherein, the target process is a process in the 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 created.
  • the device further includes: a group management module, a communication module, and a recording module; the obtaining module is further configured to obtain the start request of the target application; a group management module is configured to respond to the obtained The start request obtained by the module is used to create a target application process; the group management module is also used to create the target control group when the target application process is successfully created, and add the target application process to the Target control group; the communication module, configured to establish a communication connection with the target application process; the recording module, configured to record the state information of the target application process based on the current running state of the target application process .
  • the acquiring module is further configured to acquire a message that the sub-process of the target application process is created successfully; the communication module is also configured to establish a communication connection with the sub-process of the target application process; The group management module is configured to add the sub-process of the target application process to the target control group; the recording module is also configured to record the sub-process based on the current running state of the target application process Status information of the child processes of the target application process.
  • the obtaining module is specifically used to obtain a window focus change message; the control module is specifically used to control the process of obtaining the window focus to enter an active state; the control module is also used to When the preset condition is met, the process that loses the window focus is controlled to enter an inactive state through the target communication connection; wherein, the process that enters the inactive state will close some functions, and the process that enters the active state will re-enable the process A function that is turned off when entering the inactive state.
  • the device further includes a display module and a resource management module; the acquiring module is specifically configured to acquire a window hiding message; the control module is specifically configured to keep all windows corresponding to the first process in a hidden state In the case where the target communication connection is used, the first process is controlled to enter an invisible running state; the display module is configured to stop rendering the window of the first process; the resource management module is configured to run in the When all processes in the first process are in an invisible running state, reduce the resource priority of the first process group; wherein, the first process is: the process to which the first window belongs; the first window is: The window that needs to be hidden indicated by the window hiding message; the first process group includes: the first process, and/or, a child process of the first process.
  • the acquiring module is specifically configured to acquire a window hiding message
  • the control module is specifically configured to keep all windows corresponding to the first process in a hidden state
  • the first process is controlled to enter an invisible running state
  • the display module is configured to stop rendering the window of the first process
  • the acquiring module is specifically configured to acquire a suspension message of the second process; the acquiring module is further configured to acquire window status information of the second process; the control module is specifically configured to When the window state information indicates that the windows corresponding to the second process are all in the hidden state, send a first message to the second process through the target communication connection; the first message is used to notify the The second process retains the target data within the first preset time; the target data is the necessary data required for the second process to recover; the communication module is specifically used for when the first preset time is over , sending a SIGINT message to the second process; the control module is specifically used to control the second process to enter a suspended state; the control module is specifically used to make all processes in the second process group invisible In the running state, control the processes in the second process group to enter the suspended state; wherein, the second process group is the process group to which the second process belongs.
  • the obtaining module is specifically configured to obtain a recovery message of the second process; the recovery message is used to indicate that the second process enters a normal running state from a suspended state; the communication module is also configured to use for sending a SIGCONT message to the second process; the communication module is further used for sending a second message to the second process through the target communication connection when the second process is in a normal running state
  • the control module is specifically used to control the second process to restore the running state before the second process enters the suspended state based on the target data; the communication module is also used to send the third process to the window manager message, restoring the window corresponding to the second process.
  • the obtaining module is specifically configured to obtain application stop information of the third process; the communication module is further configured to send the third process to the third process when the third process is in a suspended state A SIGCONT message; the control module is specifically configured to control the third process to resume the running state; the communication module is also configured to send a fourth message to the third process through the target communication connection; the first process Four messages are used to instruct the third process to complete the pre-stop preparations within the second preset time; the communication module is also used to send SIGTERM to the third process when the second preset time is over message; the communication module is also used to send a SIGKILL message to the third process when the third process terminates overtime; the acquisition module is also used to acquire the information related to the target control group Process state information of a fourth process associated with the third process; the resource management module is further configured to reclaim the resources occupied by the fourth process according to a preset recycling policy based on the process state information of the fourth process .
  • the present disclosure also provides a computer program product, including a computer program/instruction, and when the computer program/instruction is executed by a processor, the steps of any one of the Linux application process management methods described above are implemented.
  • the present disclosure also provides a computer program.
  • the computer program When the computer program is executed by a processor, the steps of any one of the Linux application process management methods described above are implemented.
  • the present disclosure also provides an electronic device, including a memory, a processor, and a computer program stored on the memory and operable on the processor.
  • the processor executes the program, it implements any one of the Linux application processes described above. The steps of the management method.
  • the present disclosure also provides a non-transitory computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the Linux application process management methods described above are implemented.
  • the Linux application process management method and device obtained the process information of each process in the target control group through the target control group of the target application, and establish a communication connection with it. Afterwards, when the system obtains the process state change information of the target application in the target control group, based on the process state change information, through the target communication connection established with the target process, it sends a control letter to the target process to control the execution of the target process and The operation corresponding to the state change information further realizes the management of the entire life cycle of each process of the target application.
  • FIG. 1 is a schematic flow diagram of a Linux application process management method provided by the present disclosure
  • Fig. 2 is a schematic diagram of the startup process of the Linux application main process provided by the present disclosure
  • FIG. 3 is a schematic diagram of a sub-process startup process of a Linux application provided by the present disclosure
  • FIG. 4 is a schematic flow diagram of an application process management service controlling a process to enter an inactive running state provided by the present disclosure
  • FIG. 5 is a schematic flow diagram of the application process management service control process entering an invisible running state provided by the present disclosure
  • FIG. 6 is a schematic flow diagram of the application process management service control process entering the suspended state provided by the present disclosure
  • Fig. 7 is a schematic flow diagram of the recovery of the application process management service control process from the suspended state provided by the present disclosure
  • FIG. 8 is a schematic flow diagram of application process management service control process termination provided by the present disclosure.
  • FIG. 9 is a schematic structural diagram of a Linux application process management device provided by the present disclosure.
  • Fig. 10 is a schematic structural diagram of an electronic device provided by the present disclosure.
  • first”, “second” and the like in the specification and claims of the present disclosure are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms so used are interchangeable under appropriate circumstances such that the embodiments of the present disclosure are capable of practice in sequences other than those illustrated or described herein, and references to "first”, “second”, etc. to distinguish Objects are generally of one type, and the number of objects is not limited. For example, there may be one or more first objects.
  • “and/or” in the specification and claims means at least one of the connected objects, and the character “/” generally means that the related objects are an "or” relationship.
  • Mobile operating systems eg, Android, iOS, etc.
  • Mobile operating systems are sensitive to hardware resources and power consumption, so they all have a strong management mechanism for the application life cycle. For example, the foreground application is activated, and the background application is suspended; when system resources are tight, some applications are recycled to release resources.
  • the traditional Linux operating system is mainly developed for personal computers. There is no front-end and background concepts for applications, and there are almost no restrictions on the operation of applications. Therefore, the power consumption performance on mobile devices is not good.
  • the general Linux operating system when starting an application, simply creates a process through the fork function, executes the application startup, and does not monitor the sub-processes and grandchildren processes created by the application itself, and it is difficult to complete the suspension and recycling of associated processes and so on.
  • the application is started by a unified launcher, which cooperates with the window manager to provide basic front-end and background life cycle capabilities, and cooperates with the Linux cgroup mechanism to create an independent process management group for each application, which can manage all descendants associated with the application process, realize the control of suspension and recycling of all application-related processes, enhance the management of the life cycle of Linux applications, reduce energy consumption, improve the operating efficiency of the system, and reduce the requirements for device hardware performance.
  • a Linux application process management method provided by an embodiment of the present disclosure may include the following steps 101 and 102:
  • Step 101 acquiring process state change information of a target application.
  • the Linux application process management method provided in this embodiment is based on the cooperation between the system-level application process management service and the application-side components. Based on the application-side components, the application process management service can establish a communication connection with the application process, and then Realize the comprehensive control of the application process by the application process management service. That is, the execution subject of the Linux application process management method provided by the embodiment of the present disclosure may serve the above application process management.
  • the above-mentioned application-side component may be a program library, which is used to communicate with the above-mentioned application process management service after the application-side is integrated. That is, if the Linux application wants to communicate with the above-mentioned application process management service, it must integrate the above-mentioned application-side components.
  • the process state change information of the above-mentioned target application can be obtained by the above-mentioned 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, thereby realizing the control of the Linux process control and management.
  • the process state change information may include at least one of the following: creating a child process, making a process enter an inactive state, making a process enter an active state, hiding a process, suspending a process, resuming a process, terminating a process, and the like.
  • the inactive state of the above process means that the process is running, but the window corresponding to the process does not have the user focus;
  • the activation state of the above process means that the process is running, and the window corresponding to the process has the user focus ;
  • the hidden process above indicates that the process is running, but the window corresponding to the process is hidden.
  • the process state change information of the above-mentioned target application may be actively obtained by the above-mentioned application process management service, or may be sent to the application process management service by other system services, for example, the window manager may send a window Hide messages etc.
  • Step 102 Based on the process state change information, control the target process to execute the operation corresponding to the state change information through the target communication connection established with the target process.
  • the target process is a process in the 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 created.
  • the application process management service may, after obtaining the process state change information of the application process, use the target communication connection based on the process state change information , to send control information to the corresponding process, and the application component executes an operation corresponding to the control information after receiving the control information, and then controls the process.
  • control group control group, cgroup
  • the above-mentioned application process management service can monitor each process in the target control group through the control group, obtain the process associated with each process, and the hierarchical relationship among the processes.
  • the application process management service obtains the above-mentioned process state change information, based on the process state change information, through the above-mentioned target communication connection, the corresponding control instruction is sent to the Linux application process indicated by the process state change information to control the The Linux process executes corresponding actions, thereby realizing the management of the entire life cycle of the Linux application process from creation to termination by the application process management service.
  • the process information of each process in the target control group is obtained, and a communication connection is established with it.
  • the system obtains the process state change information of the target application in the target control group, based on the process state change information, through the target communication connection established with the target process, it sends a control letter to the target process to control the execution of the target process and
  • the operation corresponding to the state change information further realizes the management of the entire life cycle of each process of the target application.
  • the Linux application process management method may further include the following steps 103 to 106:
  • Step 103 obtaining the start request of the target application.
  • Step 104 Create a target application process in response to the start request.
  • the above-mentioned target application process is the main process of the above-mentioned target application
  • the above-mentioned target control group can be created only after the main process of the target application is created, and other processes created subsequently are also added to the target control group middle.
  • Step 105 If the target application process is created successfully, create the target control group, add the target application process to the target control group, and establish a communication connection with the target application process.
  • Step 106 Based on the current running state of the target application process, record the state information of the target application process.
  • the above-mentioned application process management service needs to record the process identification (process identification, PID) of the target application process and the current running state of the target application process, so as to facilitate subsequent Manage and get or update the current running state of the process.
  • process identification process identification, PID
  • the above-mentioned application process management service may also obtain the identity document (identity document, ID) of the window created by the target application process from the above-mentioned window manager, and record the target application process and the Status information for the window. That is, the above state information of the target application process may also include window state information of the window corresponding to the target application process.
  • FIG. 2 it is a schematic diagram of a process of starting a main process of a Linux application.
  • the application process management service obtains the program start request of the Linux application, it creates the main process of the Linux application (that is, the above-mentioned target application process) through the fork function.
  • the creation success result is fed back to the application process management service, and the PID of the main process is returned.
  • the application process management service establishes a control group for the target application based on the main process (ie, the above-mentioned target control group), and adds the PID of the main process to the management task of the application process management service.
  • the main process After the main process is successfully created, continue to execute the normal startup process of the application, and complete the startup of the Linux application.
  • the main process establishes a communication connection with the application process management service, and the application process management service sends an establishment success message to the main process after successfully establishing the communication connection with the main process.
  • the application process management service can send control instructions to the main process through the communication connection established with the main process.
  • the main process submits a window display request to the Linux window manager.
  • the window manager renders and synthesizes the window of the main process as the current window, and sets the window as the focus window .
  • the process management service after the main process of the Linux application is created successfully, the process management service also needs to establish a communication connection with the sub-process created on the basis of the main process, and record its current status.
  • the Linux application process management method provided by the embodiment of the present disclosure may further include the following steps 107 to 110:
  • Step 107 Obtain a message that the child process of the target application process is created successfully.
  • Step 108 establishing a communication connection with the child process of the target application process.
  • Step 109 Add the child process of the target application process to the target control group.
  • Step 110 based on the current running state of the sub-process of the target application process, record the status information of the sub-process of the target application process.
  • the application process management service establishes a communication connection with the sub-process after the sub-process of the Linux application is successfully created, and feeds back the result to the child process.
  • the application process management service needs to communicate with the process of the Linux application, and needs to establish a communication connection with each process of the Linux application.
  • FIG. 3 it is a schematic diagram of a sub-process startup process of a Linux application.
  • the Linux application main process needs to create a child process, it needs to request the Linux kernel to create a child process, specifically, create a child process through a fork function.
  • the Linux kernel creates a child process
  • the child process is added to the process group of its parent process (ie, the main process) through the control group cgroup created when the main process starts. Adding a certain process and its descendants to the process group of the process is for the convenience of obtaining the processes associated with the process.
  • the child process executes a specific startup process, and then establishes a communication connection with the application process management service.
  • the application process management service can establish a communication connection with all processes created by the Linux application through the above method, so as to facilitate subsequent management of each process of the Linux application through the communication connection.
  • the application process management service can realize the monitoring of the entire life cycle of each process through the communication connection established with each process in the target control group. manage.
  • Example 1 if it is desired to control a certain process in the target control group to enter the inactive state, it can be controlled according to the following control flow.
  • step 101 may include the following step 101a:
  • Step 101a acquiring a window focus change message.
  • the above window focus change message is acquired by the application process management service from the Linux window manager.
  • step 102 may include the following step 102a:
  • Step 102a control the process that acquires the window focus to enter the active state, and when the process that loses the window focus satisfies a preset condition, control the process that loses the window focus to enter the inactive state through the target communication connection.
  • the process entering the inactive state will close some functions, and the process entering the active state will re-enable the functions that were closed when the process entered the inactive state.
  • the application process management service will first determine whether the above-mentioned process that has lost the window focus satisfies a preset condition, for example, whether the process that has lost the window focus still displays windows etc. And only when the preset condition is satisfied, the process that loses the window focus will be controlled to enter the inactive running state.
  • a preset condition for example, whether the process that has lost the window focus still displays windows etc.
  • FIG. 4 it is a schematic flow diagram of the application process management service controlling the process to enter the inactive running state.
  • the application process management service obtains the window focus change message sent by the Linux window manager, the application process management service calculates the process state change according to the focus window and the status of each process group, that is, which processes enter the active running state and which processes enter the inactive state Operating status.
  • step 101 may include the following step 101b:
  • Step 101b obtaining window hiding information.
  • the window hiding message is used to control the window corresponding to the process to enter the hidden state.
  • step 102 may include the following steps 102b1 and 102b2:
  • Step 102b1 In the case that all the windows corresponding to the first process are in the hidden state, control the first process to enter an invisible running state through the target communication connection.
  • Step 102b2 stop rendering the window of the first process, and lower the resource priority of the first process group when all processes in the first process are in an invisible running state.
  • the first process is: the process to which the first window belongs; the first window is: the window that needs to be hidden indicated by the window hiding message; the first process group includes: the first process, and /or, a child process of the first process.
  • the above-mentioned first process is the target process in step 101 .
  • the above-mentioned first process and the child processes of the first process form a first process group.
  • FIG. 5 it is a schematic flow diagram of the application process management service controlling a process to enter an invisible running state.
  • the application process management service obtains the window hiding message sent by the Linux window manager, it calculates the process state change according to the state of the hidden window and each process group.
  • the Linux window manager releases the surface resource corresponding to the window that needs to be hidden.
  • the process enters an invisible running state. Afterwards, stop the rendering of the process's associated window content. And, in the case that all processes in the process group of the process are in an invisible running state, the resource priority of the process group is appropriately lowered.
  • Example 3 if you want to control a process in the target control group to enter the suspended state, you can control it according to the following control process.
  • step 101 may include the following step 101c:
  • Step 101c acquire the suspension message of the second process.
  • the suspension message is used to indicate that the second process enters a suspension state.
  • the above-mentioned second process is the target process in the above-mentioned step 101 .
  • step 102 may include the following steps 102c1 to 102c4:
  • Step 102c1 acquiring window state information of the second process.
  • the above window status information is used to indicate the current status of all windows corresponding to the second process.
  • Step 102c2 When the window state information indicates that the windows corresponding to the second process are all hidden, send a first message to the second process through the target communication connection.
  • the first message is used to notify the second process to retain target data within a first preset time; the target data is necessary data required by the second process for recovery.
  • the above-mentioned first preset time is a time for retaining necessary data required for reply before the above-mentioned second process is suspended.
  • the application process management service will first notify the second process that it will suspend the second process after the first preset time. After receiving the notification, the second process will complete the data saving within the first preset time, which is convenient for future When the process resumes, it can be restored to the current running state.
  • the state of each window needs to be considered.
  • the second process is controlled to enter the suspended state.
  • Step 102c4 When all the 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.
  • the second process group is a process group to which the above-mentioned second process belongs.
  • FIG. 6 it is a schematic flow chart of the application process management service controlling the process to enter the suspended state.
  • the application process manager obtains the message that a certain process needs to be suspended, it sends a suspension message to the suspended process, and the suspension message is used to indicate that the suspended process is at the suspension preparation time (i.e. The necessary data required for recovery is retained within a preset time), so that the process can be restored to the state before the process is suspended when the process is resumed.
  • the application process manager sends a SIGINT message to the suspended process after the suspension preparation time is over, and the Linux kernel controls the process to enter the suspended state. Finally, the application process management service marks the suspended process as suspended.
  • Example 4 based on the above-mentioned Example 3, if it is desired to control a certain process in the target control group to resume from the suspended state, control can be performed according to the following control flow.
  • step 101 may include the following step 101d:
  • Step 101d acquiring recovery information of the second process.
  • the resume message is used to instruct the second process to enter a normal running state from a suspended state.
  • step 102 may include the following steps 102d1 to 102d3:
  • Step 102d1 Send a SIGCONT message to the second process through the target communication connection.
  • the application process management service when it wants to resume the suspended second process, it may directly send a SIGCONT message to the second process.
  • Step 102d2 When the second process is in a normal running state, send a second message to the second process through the target communication connection, and control the second process to restore the first process based on the target data.
  • the running state of the second process before entering the suspended state.
  • the application process management service sends a process resume notification to the second process, and controls the second process to resume the running state based on the data retained by the second process when the process was suspended.
  • Step 102d3 Send a third message to the window manager to restore the window corresponding to the second process.
  • the application process management service pulls up the window corresponding to the second process through the window manager.
  • FIG. 7 it is a schematic flow diagram of the application process management service controlling process recovery from the suspended state.
  • the application process manager wants a process to resume from the suspended state to the normal running state, it can send a SIGINT message to the resumed process, and the Linux kernel resumes the running of the process.
  • the application process management service notifies the resumed process to restore data and status, and the resumed process performs data recovery and status recovery based on the data retained during the previous suspension.
  • the application process management service re-launches the window corresponding to the restored process by sending an instruction to the window manager.
  • Example 5 if you want to control the termination of a certain process in the target control group, you can control according to the following control flow.
  • step 101 may include the following step 101e:
  • Step 101e acquiring application stop information of the third process.
  • step 102 may include the following steps 102e1 to 102e6:
  • Step 102e1 When the third process is in a suspended state, send a SIGCONT message to the third process to control the third process to resume the running state.
  • the application process management service terminates the third process, it needs to determine whether the third process is in the suspended state. If the third process is in the suspended state, when the third process terminates, there may be some unsaved data, therefore, the third process needs to be resumed from the suspended state.
  • Step 102e2 Send a fourth message to the third process through the target communication connection.
  • the fourth message is used to instruct the third process to complete the preparatory work before stopping within the second preset time.
  • the application process management service when the third process is in a normal running state, the application process management service sends the fourth message to the third process, instructing the third process to save unsaved data within a second preset time.
  • Step 102e3 Send a SIGTERM message to the third process after the second preset time expires.
  • the application process management service sends SIGTERM to the third process to terminate the third process.
  • Step 102e4 when the third process terminates overtime, send a SIGKILL message to the third process.
  • the above SIGINT message, SIGCONT message, SIGTERM message, and SIGKILL message are Linux process control signals, and the control signal can be sent to a specified process through the Linux kernel.
  • the application process management service may also send a SIGKILL message to the third process to forcibly terminate the third process.
  • Step 102e5. Obtain process state information of a fourth process associated with the third process in the target control group.
  • Step 102e6 based on the process state information of the fourth process, reclaim the resources occupied by the fourth process according to a preset reclaim policy.
  • the application process management service also needs to perform resource recovery on the terminated process. Specifically, for the above-mentioned third process and the descendant processes created based on the third process, etc., after terminating the third process, it is possible to determine whether the above-mentioned fourth process still has windows being displayed, etc., and decide whether to recycle the windows created by the fourth process. resources used.
  • FIG. 8 it is a schematic flow diagram of application process management service control process termination.
  • the application process management service first judges whether the terminated process is in a suspended state, and if so, sends a SIGCONT message to the terminated process, and the Linux kernel resumes the operation of the suspended process. Afterwards, the application management service sends a notification to the terminated process, notifying that the process will be terminated after a certain period of time (that is, the second preset time), and the terminated process will perform pre-termination preparations after receiving the notification. , save the necessary data.
  • the application process management service sends a SIGTERM message to the terminated process, and the Linux kernel terminates the process. If the process terminates overtime, a SIGKILL message is sent to the process to forcibly terminate the process. Afterwards, the process state of the associated process of the terminated process is calculated according to the cgroup, and the process resources are recovered according to the preset resource recovery policy.
  • the application process management service can manage the entire life cycle of each process of the Linux application according to the above process management method.
  • the Linux application process management method obtains the process information of each process in the target control group through the target control group of the target application, and establishes a communication connection with it. Afterwards, when the system obtains the process state change information of the target application in the target control group, based on the process state change information, through the target communication connection established with the target process, it sends a control letter to the target process to control the execution of the target process and The operation corresponding to the state change information further realizes the management of the entire life cycle of each process of the target application.
  • the Linux application process management method provided by the embodiments of the present disclosure may be executed by 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 method for managing the Linux application process executed by the Linux application process management device is taken as an example to illustrate the Linux application process management device provided in the embodiment of the present disclosure.
  • FIG. 9 is a schematic structural diagram of a Linux application process management device provided by an embodiment of the present disclosure, as shown in FIG. 9 , specifically including:
  • the acquiring module 901 is configured to acquire the process state change information of the target application; the control module 902 is configured to control the execution of the target process through the target communication connection established with the target process based on the process state change information acquired by the acquiring module 901 An operation corresponding to the state change information; wherein, the target process is a process in the target control group of the target application; the target communication connection is a communication established with the target process when the target process is created connect.
  • the device further includes: a group management module, a communication module, and a recording module;
  • the acquisition module 901 is also configured to acquire the start request of the target application;
  • a group management module is configured to respond to the The start request obtained by the obtaining module 901 is used to create a target application process;
  • the group management module is also configured to create the target control group and add the target application process to the target application process when the target application process is successfully created The target control group;
  • the communication module configured to establish a communication connection with the target application process;
  • the recording module configured to record the target application process based on the current running state of the target application process status information.
  • the obtaining module 901 is further configured to obtain a message that the sub-process of the target application process is created successfully; the communication module is also configured to establish a communication connection with the sub-process of the target application process; The group management module is configured to add the sub-processes of the target application process to the target control group; the recording module is also configured to record the sub-processes of the target application process based on the current running status Describes the status information of the child processes of the target application process.
  • the acquiring module 901 is specifically configured to acquire window focus change messages; the control module 902 is specifically configured to control the process of acquiring window focus to enter an active state; the control module 902 is also configured to When the focused process satisfies the preset condition, control the process that loses the window focus to enter the inactive state through the target communication connection; wherein, the process that enters the inactive state will close some functions, and the process that enters the active state will Re-enable functionality that was turned off when a process went into inactive state.
  • the device further includes 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 make all windows corresponding to the first process in the In the hidden state, control the first process to enter an invisible running state through the target communication connection; the display module is configured to stop rendering the window of the first process; the resource management module is configured to In the case that all processes in the first process are in an invisible running state, reduce the resource priority of the first process group; wherein, the first process is: the process to which the first window belongs; the first window It is: the window that needs to be hidden indicated by the window hiding message; the first process group includes: the first process, and/or, a child process of the first process.
  • the obtaining module 901 is specifically configured to obtain a window hiding message
  • the control module 902 is specifically configured to make all windows corresponding to the first process in the In the hidden state, control the first process to enter an invisible running state through the target communication connection
  • the display module is configured to stop rendering the window
  • the acquiring module 901 is specifically configured to acquire the suspension message of the second process; the acquiring module 901 is further configured to acquire the window state information of the second process; the control module 902 is specifically configured to When 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 retain the target data within a first preset time; the target data is necessary data required for recovery of the second process; the communication module is specifically used for when the first preset After the time expires, send a SIGINT message to the second process through the target communication connection; the control module 902 is specifically used to control the second process to enter a suspended state; the control module 902 is specifically used to When all processes in the second process group are in an invisible running state, control the processes in the second process group to enter a suspended state; wherein, the second process group is a process to which the second process belongs Group.
  • the obtaining module 901 is specifically configured to obtain a recovery message of the second process; the recovery message is used to indicate that the second process enters a normal running state from a suspended state; the communication module is also configured to is configured to send a SIGCONT 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 running state. message; the control module 902 is specifically configured to control the second process to restore the running state of the second process before entering the suspended state based on the target data; the communication module is also configured to send a message to the window manager The third message restores the window corresponding to the second process.
  • the acquiring module 901 is specifically configured to acquire application stop information of the third process; the communication module is further configured to send the third process Sending a SIGCONT message; the control module 902 is specifically configured to control the third process to resume the running state; the communication module is also configured to send a fourth message to the third process through the target communication connection; The fourth message is used to instruct the third process to complete the pre-stop preparations within a second preset time; the communication module is also used to send a message to the third process after the second preset time sending a SIGTERM message; the communication module is further configured to send a SIGKILL message to the third process when the third process terminates overtime; the acquisition module 901 is also configured to acquire the target control group The process state information of the fourth process associated with the third process; the resource management module is further configured to reclaim the fourth process according to the preset recycling policy based on the process state information of the fourth process resources used.
  • the Linux application process management device obtains the process information of each process in the target control group through the target control group of the target application, and establishes a communication connection with it. Afterwards, when the system obtains the process state change information of the target application in the target control group, based on the process state change information, through the target communication connection established with the target process, it sends a control letter to the target process to control the execution of the target process and The operation corresponding to the state change information further realizes the management of the entire life cycle of each process of the target application.
  • Figure 10 illustrates a schematic diagram of the physical structure of an electronic device, as shown in Figure 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 through the communication bus 1040 .
  • processor processor
  • Communication interface Communication Interface
  • memory memory
  • the processor 1010 can call the logic instructions in the memory 1030 to execute the Linux application process management method, the method includes: acquiring process state change information of the target application; based on the process state change information, passing the target A communication connection, controlling the target process to execute an operation corresponding to the state change information; wherein, the target process is a process in the target control group of the target application; the target communication connection is created with the target process The communication connection established by the target process.
  • the logic instructions in the above-mentioned memory 1030 can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
  • the technical solution of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present disclosure.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disc, etc., which can store program codes. .
  • the present disclosure also provides a computer program product
  • the computer program product includes a computer program stored on a non-transitory computer-readable storage medium
  • the computer program includes program instructions, and when the program instructions are executed by a computer
  • the computer can execute the Linux application process management method provided by the above-mentioned methods, and the method includes: obtaining the process state change information of the target application; based on the process state change information, through the target communication established with the target process connection, to control the target process to execute the operation corresponding to the state change information; wherein, the target process is a process in the target control group of the target application; the target communication connection is when the target process is created and the Describes the communication connection established by the target process.
  • the present disclosure also provides a computer program
  • the computer program includes program instructions, when the program instructions are executed by the computer, the computer can execute the Linux application process management method provided by the above methods, the method includes : Acquiring process state change information of a target application; based on the process state change information, controlling the target process to perform an operation corresponding to the state change information through a target communication connection established with the target process; wherein, the target process 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 created.
  • the present disclosure also provides a non-transitory computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it is implemented to execute the Linux application process management methods provided above, the method includes : Acquiring process state change information of a target application; based on the process state change information, controlling the target process to perform an operation corresponding to the state change information through a target communication connection established with the target process; wherein, the target process 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 created.
  • the device embodiments described above are only illustrative, and the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in One place, or it can be distributed to multiple network elements. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. It can be understood and implemented by those skilled in the art without any creative effort.
  • each implementation can be implemented by means of software plus a necessary general-purpose hardware platform, and of course also by hardware.
  • the essence of the above technical solution or the part that contributes to the prior art can be embodied in the form of software products, and the computer software products can be stored in computer-readable storage media, such as ROM/RAM, magnetic discs, optical discs, etc., including several instructions to make a computer device (which may be a personal computer, server, or network device, etc.) execute the methods described in various embodiments or some parts of the embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本公开提供一种Linux应用进程管理方法及装置,该方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。

Description

Linux应用进程管理方法及装置
相关申请的交叉引用
本公开要求于2021年11月17日提交的、申请号为202111358725.4、名称为“Linux应用进程管理方法及装置”的中国专利申请的优先权,其全部内容通过引用并入本文。
技术领域
本公开涉及Linux系统软件开发领域,尤其涉及一种Linux应用进程管理方法及装置。
背景技术
随着移动通信技术的发展,移动设备上的操作系统(例如,Android、iOS等)基于移动设备功耗及资源敏感的考虑,均有对应用的前后台进程的强生命周期管理机制。
然而,面向个人计算机的Linux操作系统,并没有前后台的概念,也没有相应的系统服务框架支持对应用进程生命周期的管理,导致Linux应用缺乏有效的前后台进程管理机制。
发明内容
本公开的目的是提供一种Linux应用进程管理方法及装置,用于增强Linux应用的前后台进程管理。
本公开提供一种Linux应用进程管理方法,包括:
获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
可选地,所述获取目标应用的进程状态变更信息之前,所述方法还包括:获取所述目标应用的启动请求;响应于所述启动请求,创建目标应用进程;在所述目标应用进程创建成功的情况下,创建所述目标控制群组,将所述目标应用进程加入所述目标控制群组,并建立与所述目标应用进程的通信连接;基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息。
可选地,所述基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息之后,所述方法还包括:获取所述目标应用进程的子进程创建成功的消息;建立与所述目标应用进程的子进程间的通信连接;将所述目标应用进程的子进程加入所述目标控制群组;基于所述目标应用进程的子进程的当前运行状态,记录所述目标应用进程的子进程的状态信息。
可选地,所述获取目标应用的进程状态变更信息,包括:获取窗口焦点变更消息;所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:控制获取窗口焦点的进程进入激活状态,并在失去窗口焦点的进程满足预设条件的情况下,通过所述目标通信连接,控制所述失去窗口焦点的进程进入非激活状态;其中,进入非激活状态的进程会关闭部分功能,进入激活状态的进程会重新启用进程进入非激活状态时关闭的功能。
可选地,所述获取目标应用的进程状态变更信息,包括:获取窗口隐藏消息;所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:在第一进程所对应的窗口全部处于隐藏状态的情况下,通过所述目标通信连接,控制所述第一进程进入不可见运行状态;停止渲染所述第一进程的窗口,并在所述第一进程中所有进程均处于不可见运行状态的情况下,降低第一进程组的资源优先级;其中,所述第一进程为:第一窗口所属的进程;所述第一窗口为:所述窗口隐藏消息指示的需要隐藏的窗口;所述第一进程组包括:所述第一进程,和/或,所述第一进程的子进程。
可选地,所述获取目标应用的进程状态变更信息,包括:获取第二进程的挂起消息;所述挂起消息用于指示所述第二进程进入挂起状态;所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:获取所述第二进程的窗口状态信息;在所述窗口状态信息指示所述第二进程所对应的窗口均处于隐藏状态的情况下,通过所述目标通信连接,向所述第二进程发送第一消息;所述第一消息用于通知所述第二进程在第一预设时间内保留目标数据;所述目标数据为所述第二进程恢复时所需的必要数据;当所述第一预设时间结束后,向所述第二进程发送SIGINT消息,控制所述第二进程进入挂起状态;在第二进程组中的所有进程处于不可见运行状态的情况下,控制所述第二进程组中的进程进入挂起状态;其中,所述第二进程组为所述第二进程所属的进程组。
可选地,所述获取目标应用的进程状态变更信息,包括:获取所述第二进程的恢复消 息;所述恢复消息用于指示所述第二进程从挂起状态进入正常运行状态;所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:向所述第二进程发送SIGCONT消息;在所述第二进程处于正常运行状态的情况下,通过所述目标通信连接,向所述第二进程发送第二消息,控制所述第二进程基于所述目标数据恢复所述第二进程进入挂起状态前的运行状态;向窗口管理器发送第三消息,恢复所述第二进程对应的窗口。
可选地,所述获取目标应用的进程状态变更信息,包括:所述获取目标应用的进程状态变更信息,包括:获取第三进程的应用停止信息;所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:在所述第三进程处于挂起状态的情况下,向所述第三进程发送SIGCONT消息,控制所述第三进程恢复运行状态;通过所述目标通信连接,向所述第三进程发送第四消息;所述第四消息用于指示所述第三进程在第二预设时间内完成停止前准备工作;当所述第二预设时间结束后,向所述第三进程发送SIGTERM消息;在所述第三进程终止超时的情况下,通过所述目标通信连接,向所述第三进程发送SIGKILL消息;获取所述目标控制群组内与所述第三进程相关联的第四进程的进程状态信息;基于所述第四进程的进程状态信息,按照预设回收策略回收所述第四进程所占用的资源。
本公开还提供一种Linux应用进程管理装置,包括:
获取模块,用于获取目标应用的进程状态变更信息;控制模块,用于基于所述获取模块获取的进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
可选地,所述装置还包括:群组管理模块、通信模块和记录模块;所述获取模块,还用于获取所述目标应用的启动请求;群组管理模块,用于响应于所述获取模块获取的启动请求,创建目标应用进程;所述群组管理模块,还用于在所述目标应用进程创建成功的情况下,创建所述目标控制群组,将所述目标应用进程加入所述目标控制群组;所述通信模块,用于建立与所述目标应用进程的通信连接;所述记录模块,用于基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息。
可选地,所述获取模块,还用于获取所述目标应用进程的子进程创建成功的消息;所述通信模块,还用于建立与所述目标应用进程的子进程间的通信连接;所述群组管理模块,用于将所述目标应用进程的子进程加入所述目标控制群组;所述记录模块,还用于基于所 述目标应用进程的子进程的当前运行状态,记录所述目标应用进程的子进程的状态信息。
可选地,所述获取模块,具体用于获取窗口焦点变更消息;所述控制模块,具体用于控制获取窗口焦点的进程进入激活状态;所述控制模块,还用于在失去窗口焦点的进程满足预设条件的情况下,通过所述目标通信连接,控制所述失去窗口焦点的进程进入非激活状态;其中,进入非激活状态的进程会关闭部分功能,进入激活状态的进程会重新启用进程进入非激活状态时关闭的功能。
可选地,所述装置还包括,显示模块和资源管理模块;所述获取模块,具体用于获取窗口隐藏消息;所述控制模块,具体用于在第一进程所对应的窗口全部处于隐藏状态的情况下,通过所述目标通信连接,控制所述第一进程进入不可见运行状态;所述显示模块,用于停止渲染所述第一进程的窗口;所述资源管理模块,用于在所述第一进程中所有进程均处于不可见运行状态的情况下,降低第一进程组的资源优先级;其中,所述第一进程为:第一窗口所属的进程;所述第一窗口为:所述窗口隐藏消息指示的需要隐藏的窗口;所述第一进程组包括:所述第一进程,和/或,所述第一进程的子进程。
可选地,所述获取模块,具体用于获取第二进程的挂起消息;所述获取模块,还用于获取所述第二进程的窗口状态信息;所述控制模块,具体用于在所述窗口状态信息指示所述第二进程所对应的窗口均处于隐藏状态的情况下,通过所述目标通信连接,向所述第二进程发送第一消息;所述第一消息用于通知所述第二进程在第一预设时间内保留目标数据;所述目标数据为所述第二进程恢复时所需的必要数据;所述通信模块,具体用于当所述第一预设时间结束后,向所述第二进程发送SIGINT消息;所述控制模块,具体用于控制所述第二进程进入挂起状态;所述控制模块,具体用于在第二进程组中的所有进程处于不可见运行状态的情况下,控制所述第二进程组中的进程进入挂起状态;其中,所述第二进程组为所述第二进程所属的进程组。
可选地,所述获取模块,具体用于获取所述第二进程的恢复消息;所述恢复消息用于指示所述第二进程从挂起状态进入正常运行状态;所述通信模块,还用于向所述第二进程发送SIGCONT消息;所述通信模块,还用于在所述第二进程处于正常运行状态的情况下,通过所述目标通信连接,向所述第二进程发送第二消息;所述控制模块,具体用于控制所述第二进程基于所述目标数据恢复所述第二进程进入挂起状态前的运行状态;所述通信模块,还用于向窗口管理器发送第三消息,恢复所述第二进程对应的窗口。
可选地,所述获取模块,具体用于获取第三进程的应用停止信息;所述通信模块,还用于在所述第三进程处于挂起状态的情况下,向所述第三进程发送SIGCONT消息;所述 控制模块,具体用于控制所述第三进程恢复运行状态;所述通信模块,还用于通过所述目标通信连接,向所述第三进程发送第四消息;所述第四消息用于指示所述第三进程在第二预设时间内完成停止前准备工作;所述通信模块,还用于当所述第二预设时间结束后,向所述第三进程发送SIGTERM消息;所述通信模块,还用于在所述第三进程终止超时的情况下,向所述第三进程发送SIGKILL消息;所述获取模块,还用于获取所述目标控制群组内与所述第三进程相关联的第四进程的进程状态信息;所述资源管理模块,还用于基于所述第四进程的进程状态信息,按照预设回收策略回收所述第四进程所占用的资源。
本公开还提供一种计算机程序产品,包括计算机程序/指令,所述计算机程序/指令被处理器执行时实现如上述任一种所述Linux应用进程管理方法的步骤。
本公开还提供一种计算机程序,所述计算机程序被处理器执行时实现如上述任一种所述Linux应用进程管理方法的步骤。
本公开还提供一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现如上述任一种所述Linux应用进程管理方法的步骤。
本公开还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现如上述任一种所述Linux应用进程管理方法的步骤。
本公开提供的Linux应用进程管理方法及装置,通过目标应用的目标控制群组,获取该目标控制群组中每个进程的进程信息,并与之建立通信连接。之后,当系统获取到目标控制群组中目标应用的进程状态变更信息时,基于该进程状态变更信息,通过与目标进程建立的目标通信连接,向该目标进程发送控制信,控制目标进程执行与所述状态变更信息对应的操作,进而实现对目标应用的每个进程整个生命周期的管理。
附图说明
为了更清楚地说明本公开或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单的介绍,显而易见地,下面描述中的附图是本公开的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本公开提供的Linux应用进程管理方法的流程示意图;
图2是本公开提供的Linux应用主进程启动流程示意图;
图3是本公开提供的Linux应用的子进程启动流程示意图;
图4是本公开提供的应用进程管理服务控制进程进入非激活运行状态的流程示意图;
图5是本公开提供的应用进程管理服务控制进程进入不可见运行状态的流程示意图;
图6是本公开提供的应用进程管理服务控制进程进入挂起状态的流程示意图;
图7是本公开提供的应用进程管理服务控制进程从挂起状态恢复的流程示意图;
图8是本公开提供的应用进程管理服务控制进程终止的流程示意图;
图9是本公开提供的Linux应用进程管理装置的结构示意图;
图10是本公开提供的电子设备的结构示意图。
具体实施方式
为使本公开的目的、技术方案和优点更加清楚,下面将结合本公开中的附图,对本公开中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本公开一部分实施例,而不是全部的实施例。基于本公开中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本公开保护的范围。
本公开的说明书和权利要求书中的术语“第一”、“第二”等是用于区别类似的对象,而不用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便本公开的实施例能够以除了在这里图示或描述的那些以外的顺序实施,且“第一”、“第二”等所区分的对象通常为一类,并不限定对象的个数,例如第一对象可以是一个,也可以是多个。此外,说明书以及权利要求中“和/或”表示所连接对象的至少其中之一,字符“/”,一般表示前后关联对象是一种“或”的关系。
移动操作系统(例如,Android、iOS等)由于对硬件资源及功耗敏感,都会有对应用生命周期的强管理机制。例如,前台应用激活,后台应用暂停;在系统资源紧张时,回收部分应用来释放资源。传统Linux操作系统,主要面向个人计算机开发,应用没有前后台概念,对应用也几乎没有运行限制,所以在移动设备上的功耗表现不好。另外,一般的Linux操作系统,启动应用时,只是简单通过fork功能创建进程,执行应用启动,并没有对应用后续自行创建的子进程以及孙进程等做监控,不易完成对关联进程的暂停及回收等操作。
本方法中应用由统一的启动器启动,配合窗口管理器,提供基本的前后台生命周期能力,配合Linux的cgroup机制,为每个应用创建独立的进程管理组,可以管理到应用关联的所有子孙进程,实现全部应用关联进程的暂停,回收等控制,增强了对Linux应用生命周期的管理,降低了能耗,提升了系统的运行效率,降低对设备硬件性能的要求。
下面结合附图,通过具体的实施例及其应用场景对本公开实施例提供的Linux应用进程管理方法进行详细地说明。
如图1所示,本公开实施例提供的一种Linux应用进程管理方法,该方法可以包括下述步骤101和步骤102:
步骤101、获取目标应用的进程状态变更信息。
示例性地,本实施例提供的Linux应用进程管理方法,基于系统级的应用进程管理服务与应用端组件的配合,基于应用端的组件,应用进程管理服务可以与应用的进程间建立通信连接,进而实现应用进程管理服务对应用进程的全方位控制。即本公开实施例提供的Linux应用进程管理方法的执行主体可以为上述应用进程管理服务。
示例性地,上述应用端组件可以为一个程序库,用于应用端集成后实现与上述应用进程管理服务的通信。即,Linux应用若想要实现与上述应用进程管理服务的通信,则必须集成上述应用端组件。
示例性地,上述目标应用的进程状态变更信息可以为上述应用进程管理服务获取的,并基于该进程状态变更信息,向Linux应用进程发送与进程状态变更信息对应的控制指令,进而实现对Linux进程的控制与管理。
示例性地,上述进程状态变更信息可以包括以下至少一项:创建子进程,使进程进入非激活状态,使进程进入激活状态,隐藏进程,挂起进程,恢复进程,终止进程等。可以理解的是,上述进程的非激活状态表示该进程正在运行,但该进程所对应的窗口不拥有用户焦点;上述进程的激活状态表示该进程正在运行,且该进程所对应的窗口拥有用户焦点;上述隐藏进程表示,该进程正在运行,但该进程对应的窗口被隐藏。
示例性地,上述目标应用的进程状态变更信息可以是上述应用进程管理服务主动获取的,也可以是其他系统服务发送给应用进程管理服务的,例如,窗口管理器可以向应用进程管理服务发送窗口隐藏消息等。
步骤102、基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作。
其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
可以理解的是,基于上述应用进程管理服务与应用进程间建立的目标通信连接,应用进程管理服务可以在获取到应用进程的进程状态变更信息后,基于该进程状态变更信息,通过该目标通信连接,向对应的进程发送控制信息,应用端组件在接收到该控制信息后, 执行与该控制信息对应的操作,进而控制该进程。
示例性地,Linux应用在创建后,基于该应用的主进程创建的所有子进程以及孙子进程均被纳入同一个控制群组(control group,cgroup)中,即上述目标控制群组。上述应用进程管理服务可以通过该控制群组对目标控制群组中每个进程进行监控,获取每个进程所关联的进程,以及进程间的层级关系等。
示例性地,应用进程管理服务在获取到上述进程状态变更信息后,基于该进程状态变更信息,通过上述目标通信连接,向该进程状态变更信息指示的Linux应用进程发送对应的控制指令,控制该Linux进程执行相应的动作,进而实现应用进程管理服务对Linux应用进程从创建到终止的整个生命周期的管理。
如此,通过目标应用的目标控制群组,获取该目标控制群组中每个进程的进程信息,并与之建立通信连接。之后,当系统获取到目标控制群组中目标应用的进程状态变更信息时,基于该进程状态变更信息,通过与目标进程建立的目标通信连接,向该目标进程发送控制信,控制目标进程执行与所述状态变更信息对应的操作,进而实现对目标应用的每个进程整个生命周期的管理。
可选地,在本公开实施例中,若想要实现对Linux应用进程的生命周期管理,基于该Linux应用,创建该Linux应用的所有进程的控制群组。
示例性地,上述步骤101之前,本公开实施例提供的Linux应用进程管理方法,还可以包括以下步骤103至步骤106:
步骤103、获取所述目标应用的启动请求.
步骤104、响应于所述启动请求,创建目标应用进程。
示例性地,上述目标应用进程为上述目标应用的主进程,在该目标应用的主进程创建后,才能够创建上述目标控制群组,并将后续创建的其他进程也添加至该目标控制群组中。
步骤105、在所述目标应用进程创建成功的情况下,创建所述目标控制群组,将所述目标应用进程加入所述目标控制群组,并建立与所述目标应用进程的通信连接。
步骤106、基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息。
示例性地,在上述目标应用进程创建成功后,上述应用进程管理服务需要记录该目标应用进程的进程标识(process identification,PID),以及该目标应用进程的当前运行状态,以方便后续对该进程进行管理以及获取或更新该进程的当前运行状态。
示例性地,在上述目标应用启动完成后,上述应用进程管理服务还可以从上述窗口管 理器获取目标应用进程所创建的窗口的身份标识(identity document,ID),并记录该目标应用进程以及该窗口的状态信息。即上述目标应用进程的状态信息还可以包括该目标应用进程所对应窗口的窗口状态信息。
举例说明,如图2所示,为Linux应用主进程启动流程示意图。应用进程管理服务在获取到Linux应用的程序启动请求后,通过fork功能创建该Linux应用的主进程(即上述目标应用进程)。该主进程创建成功后,向应用进程管理服务反馈创建成功结果,并返回该主进程的PID。之后,应用进程管理服务基于该主进程为该目标应用建立控制群组(即上述目标控制群组),并将该主进程的PID添加至应用进程管理服务的管理任务中。对于Linux应用,在主进程创建成功后,继续执行应用的正常启动流程,并完成该Linux应用的启动。
在Linux应用启动流程完成后,该主进程建立与应用进程管理服务间的通信连接,应用进程管理服务在成功建立与主进程的通信连接后,向该主进程发送建立成功消息。应用进程管理服务可以通过与主进程间建立的通信连接,向该主进程发送控制指令。
在主进程启动流程完成后,该主进程向Linux窗口管理器提交窗口显示请求,窗口管理器在接收到该请求后,将主进程的窗口作为当前窗口渲染合成,并将该窗口设置为焦点窗口。
进一步可选地,在本公开实施例中,在Linux应用的主进程创建成功后,对于在该主进程基础上创建的子进程,进程管理服务也需要与其建立通信连接,并记录其当前状态。
示例性地,上述步骤106之后,本公开实施例提供的Linux应用进程管理方法,还可以包括以下步骤107至步骤110:
步骤107、获取所述目标应用进程的子进程创建成功的消息。
步骤108、建立与所述目标应用进程的子进程间的通信连接。
步骤109、将所述目标应用进程的子进程加入所述目标控制群组。
步骤110、基于所述目标应用进程的子进程的当前运行状态,记录所述目标应用进程的子进程的状态信息。
示例性地,与上述Linux应用的主进程的创建流程类似,应用进程管理服务在Linux应用的子进程创建成功后,与该子进程建立通信连接,并在成功建立通信连接后,将结果反馈至子进程。
可以理解的是,应用进程管理服务需要与Linux应用的进程进行通信,需要与Linux应用的每个进程都建立通信连接。
举例说明,如图3所示,为Linux应用的子进程启动流程示意图。当Linux应用主进程需要创建子进程时,需要向Linux内核请求创建子进程,具体地,通过fork功能创建子进程。Linux内核创建子进程后,通过主进程启动时创建的控制群组cgroup将子进程加入其父进程(即主进程)的进程组。将某个进程以及该进程的子孙进程加入该进程的进程组,是为了方便获取与该进程相关联的进程。
Linux内核创建子进程成功后,子进程执行具体的启动流程,之后,创建与应用进程管理服务间的通信连接。
如此,应用进程管理服务可以通过以上方法,与Linux应用创建的所有进程建立通信连接,方便后续通过该通信连接管理Linux应用的每个进程。
可选地,在本公开实施例中,基于上述已经创建的目标控制群组,应用进程管理服务可以通过与目标控制群组中每个进程建立的通信连接,实现对每个进程整个生命周期的管理。
示例性地,基于进程的不同状态,本公开实施例提供的以下示例,具体描述了如何通过应用进程管理服务实现对进程的管理。
示例1:
在示例1中,若想要控制目标控制群组中的某个进程进入非激活状态,则可以按照以下控制流程进行控制。
示例性地,上述步骤101可以包括以下步骤101a:
步骤101a、获取窗口焦点变更消息。
示例性地,上述窗口焦点变更消息为应用进程管理服务从Linux窗口管理器获取的。
示例性地,上述步骤102可以包括以下步骤102a:
步骤102a、控制获取窗口焦点的进程进入激活状态,并在失去窗口焦点的进程满足预设条件的情况下,通过所述目标通信连接,控制所述失去窗口焦点的进程进入非激活状态。
其中,进入非激活状态的进程会关闭部分功能,进入激活状态的进程会重新启用进程进入非激活状态时关闭的功能。
示例性地,区别于通过Linux控制指令直接控制某个进程的窗口焦点变更,应用进程管理服务会先判断上述失去窗口焦点的进程是否满足预设条件,例如,失去窗口焦点的进程是否还有显示的窗口等。并在满足预设条件的情况下,才会控制失去窗口焦点的进程进入非激活运行状态。
举例说明,如图4所示,为应用进程管理服务控制进程进入非激活运行状态的流程示 意图。应用进程管理服务在获取到Linux窗口管理器发送的窗口焦点变更消息后,应用进程管理服务根据焦点窗口及各进程组状态,计算进程状态变更,即哪些进程进入激活运行状态,哪些进程进入非激活运行状态。
对于获取焦点的进程,重新激活相关功能,并进入激活运行状态,对于失去焦点的进程,暂停相关功能,并进入非激活运行状态。
示例2:
在示例2中,若想要控制目标控制群组中的某个进程进入不可见运行状态,则可以按照以下控制流程进行控制。
示例性地,上述步骤101,可以包括以下步骤101b:
步骤101b、获取窗口隐藏消息。
示例性地,该窗口隐藏消息用于控制进程对应的窗口进入隐藏状态。
示例性地,上述步骤102,可以包括以下步骤102b1和步骤102b2:
步骤102b1、在第一进程所对应的窗口全部处于隐藏状态的情况下,通过所述目标通信连接,控制所述第一进程进入不可见运行状态。
步骤102b2、停止渲染所述第一进程的窗口,并在所述第一进程中所有进程均处于不可见运行状态的情况下,降低第一进程组的资源优先级。
其中,所述第一进程为:第一窗口所属的进程;所述第一窗口为:所述窗口隐藏消息指示的需要隐藏的窗口;所述第一进程组包括:所述第一进程,和/或,所述第一进程的子进程。
示例性地,上述第一进程即为步骤101中的目标进程。上述第一进程以及第一进程的子进程组成第一进程组。
举例说明,如图5所示,为应用进程管理服务控制进程进入不可见运行状态的流程示意图。应用进程管理服务在获取到Linux窗口管理器发送的窗口隐藏消息后,根据隐藏窗口及各进程组状态,计算进程状态变更,同时,Linux窗口管理器释放需要隐藏的窗口对应的surface资源。
若所要隐藏的窗口所属的进程的全部窗口均隐藏不可见,则该进程进入不可见运行状态。之后,停止该进程相关窗口内容的渲染。并且,在该进程的进程组中所有进程均处于不可见运行状态的情况下,适当降低该进程组的资源优先级。
示例3:
在示例3中,若想要控制目标控制群组中的某个进程进入挂起状态,则可以按照以下 控制流程进行控制。
示例性地,上述步骤101,可以包括以下步骤101c:
步骤101c、获取第二进程的挂起消息。
其中,所述挂起消息用于指示所述第二进程进入挂起状态。
示例性地,上述第二进程为上述步骤101中的目标进程。
示例性地,上述步骤102,可以包括以下步骤102c1至步骤102c4:
步骤102c1、获取所述第二进程的窗口状态信息。
示例性地,上述窗口状态信息用于指示第二进程所对应的所有窗口的当前状态。
步骤102c2、在所述窗口状态信息指示所述第二进程所对应的窗口均处于隐藏状态的情况下,通过所述目标通信连接,向所述第二进程发送第一消息。
其中,所述第一消息用于通知所述第二进程在第一预设时间内保留目标数据;所述目标数据为所述第二进程恢复时所需的必要数据。
示例性地,上述第一预设时间为上述第二进程挂起之前保留回复时所需要的必要数据的时间。应用进程管理服务会首先通知第二进程将在第一预设时间后将该第二进程挂起,第二进程在接收到该通知后,在第一预设时间内完成数据的保存,方便以后进程恢复时能够恢复到当前的运行状态。
步骤102c3、当所述第一预设时间结束后,向所述第二进程发送SIGINT消息,控制所述第二进程进入挂起状态。
示例性地,若上述第二进程对应多个窗口,则需要考虑每个窗口的状态。在第二进程所对应的窗口均处于隐藏状态的情况下,控制该第二进程进入挂起状态。
步骤102c4、在第二进程组中的所有进程处于不可见运行状态的情况下,控制所述第二进程组中的进程进入挂起状态。
其中,所述第二进程组为上述第二进程所属的进程组。
示例性地,基于上述步骤,当进程进入挂起状态后,降低该进程对系统资源的占用。
举例说明,如图6所示,为应用进程管理服务控制进程进入挂起状态的流程示意图。应用进程管理器在获取到需要挂起某个进程的消息后,向该被挂起的进程发送挂起消息,该挂起消息用于指示被挂起的进程在挂起准备时间(即上述第一预设时间)内保留恢复时所需的必要数据,方便在恢复该进程时能够将该进程恢复至挂起之前的状态。
之后,应用进程管理器在上述挂起准备时间结束后,向被挂起的进程发送SIGINT消息,Linux内核控制该进程进入挂起状态。最后,应用进程管理服务将该被挂起的进程标 记为挂起状态。
示例4:
在示例4中,基于上述示例3,若想要控制目标控制群组中的某个进程从挂起状态恢复,则可以按照以下控制流程进行控制。
示例性地,上述步骤101,可以包括以下步骤101d:
步骤101d、获取所述第二进程的恢复消息。
其中,所述恢复消息用于指示所述第二进程从挂起状态进入正常运行状态。
示例性地,上述步骤102,可以包括以下步骤102d1至步骤102d3:
步骤102d1、通过所述目标通信连接,向所述第二进程发送SIGCONT消息。
示例性地,应用进程管理服务想要恢复被挂起的第二进程时,可以直接向该第二进程发送SIGCONT消息。
步骤102d2、在所述第二进程处于正常运行状态的情况下,通过所述目标通信连接,向所述第二进程发送第二消息,控制所述第二进程基于所述目标数据恢复所述第二进程进入挂起状态前的运行状态。
示例性地,当第二进程从挂起状态恢复后,应用进程管理服务向该第二进程发送进程恢复通知,控制第二进程基于该第二进程在进程挂起时保留的数据恢复运行状态。
步骤102d3、向窗口管理器发送第三消息,恢复所述第二进程对应的窗口。
示例性地,应用进程管理服务在第二进程的数据及状态恢复后,通过窗口管理器重新拉起第二进程对应的窗口。
举例说明,如图7所示,为应用进程管理服务控制进程从挂起状态恢复的流程示意图。若应用进程管理器想要某个进程从挂起状态恢复为正常运行状态,则可以向被恢复的进程发送SIGINT消息,Linux内核恢复该进程的运行。之后,应用进程管理服务通知被恢复的进程恢复数据及状态,被恢复的进程基于之前挂起时保留的数据进行数据恢复及状态恢复。最后,应用进程管理服务,通过向窗口管理器发送指令的方式,重新拉起被恢复的进程对应的窗口。
示例5:
在示例5中,若想要控制目标控制群组中的某个进程终止,则可以按照以下控制流程进行控制。
示例性地,上述步骤101,可以包括以下步骤101e:
步骤101e、获取第三进程的应用停止信息。
示例性地,上述步骤102,可以包括以下步骤102e1至步骤102e6:
步骤102e1、在所述第三进程处于挂起状态的情况下,向所述第三进程发送SIGCONT消息,控制所述第三进程恢复运行状态。
示例性地,应用进程管理服务在终止第三进程时,需要判断该第三进程是否处于挂起状态,若该第三进程处于挂起状态,则该第三进程终止时,可能存在部分未保存的数据,因此,需要将该第三进程从挂起状态恢复。
步骤102e2、通过所述目标通信连接,向所述第三进程发送第四消息。
其中,所述第四消息用于指示所述第三进程在第二预设时间内完成停止前准备工作。
示例性地,在该第三进程处于正常运行状态的情况下,应用进程管理服务向第三进程发送上述第四消息,指示该第三进程在第二预设时间内保存好未保存的数据。
步骤102e3、当所述第二预设时间结束后,向所述第三进程发送SIGTERM消息。
示例性地,在上述第二预设时间结束后,应用进程管理服务再向第三进程发送SIGTERM,终止该第三进程。
步骤102e4、在所述第三进程终止超时的情况下,向所述第三进程发送SIGKILL消息。
示例性地,上述SIGINT消、SIGCONT消息、SIGTERM消息以及SIGKILL消息为Linux进程控制信号,该控制信号可以通过Linux内核发送至指定的进程。
示例性地,若上述第三进程终止超时,则应用进程管理服务还可以向第三进程发送SIGKILL消息,强制终止该第三进程。
步骤102e5、获取所述目标控制群组内与所述第三进程相关联的第四进程的进程状态信息。
步骤102e6、基于所述第四进程的进程状态信息,按照预设回收策略回收所述第四进程所占用的资源。
示例性地,在进程终止后,应用进程管理服务还需要对终止的进程进行资源回收。具体地,对于上述第三进程与基于该第三进程创建的子孙进程等,在终止第三进程后,可以判断上述第四进程是否还存在有正在显示的窗口等,决定是否回收第四进程所占用的资源。
举例说明,如图8所示,为应用进程管理服务控制进程终止的流程示意图。应用进程管理服务首先判断被终止的进程是否处于挂起状态,若是,则向被终止的进程发送SIGCONT消息,Linux内核恢复被挂起的进程运行。之后,应用管理服务向被终止的进程发送通知,通知该进程即将在一定时间(即上述第二预设时间)后被终止,被终止的进程在接收到该消通知后,执行终止前准备工作,保存必要的数据。
应用进程管理服务在上述时间结束后,向被终止的进程发送SIGTERM消息,Linux内核终止该进程。若该进程终止超时,则向该进程发送SIGKILL消息,强制终止该进程。之后,根据cgroup计算被终止进程的关联进程的进程状态,按预设资源回收策略进程资源回收。
如此,应用进程管理服务可以按照上述进程管理方法,对Linux应用的每个进程的整个生命周期进行管理。
本公开实施例提供的Linux应用进程管理方法,通过目标应用的目标控制群组,获取该目标控制群组中每个进程的进程信息,并与之建立通信连接。之后,当系统获取到目标控制群组中目标应用的进程状态变更信息时,基于该进程状态变更信息,通过与目标进程建立的目标通信连接,向该目标进程发送控制信,控制目标进程执行与所述状态变更信息对应的操作,进而实现对目标应用的每个进程整个生命周期的管理。
需要说明的是,本公开实施例提供的Linux应用进程管理方法,执行主体可以为Linux应用进程管理装置,或者该Linux应用进程管理装置中的用于执行Linux应用进程管理方法的控制模块。本公开实施例中以Linux应用进程管理装置执行Linux应用进程管理方法为例,说明本公开实施例提供的Linux应用进程管理装置。
需要说明的是,本公开实施例中,上述各个方法附图所示的。Linux应用进程管理方法均是以结合本公开实施例中的一个附图为例示例性的说明的。具体实现时,上述各个方法附图所示的Linux应用进程管理方法还可以结合上述实施例中示意的其它可以结合的任意附图实现,此处不再赘述。
下面对本公开提供的进行描述,下文描述的与上文描述的Linux应用进程管理方法可相互对应参照。
图9为本公开一实施例提供的Linux应用进程管理装置的结构示意图,如图9所示,具体包括:
获取模块901,用于获取目标应用的进程状态变更信息;控制模块902,用于基于所述获取模块901获取的进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
可选地,所述装置还包括:群组管理模块、通信模块和记录模块;所述获取模块901,还用于获取所述目标应用的启动请求;群组管理模块,用于响应于所述获取模块901获取 的启动请求,创建目标应用进程;所述群组管理模块,还用于在所述目标应用进程创建成功的情况下,创建所述目标控制群组,将所述目标应用进程加入所述目标控制群组;所述通信模块,用于建立与所述目标应用进程的通信连接;所述记录模块,用于基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息。
可选地,所述获取模块901,还用于获取所述目标应用进程的子进程创建成功的消息;所述通信模块,还用于建立与所述目标应用进程的子进程间的通信连接;所述群组管理模块,用于将所述目标应用进程的子进程加入所述目标控制群组;所述记录模块,还用于基于所述目标应用进程的子进程的当前运行状态,记录所述目标应用进程的子进程的状态信息。
可选地,所述获取模块901,具体用于获取窗口焦点变更消息;所述控制模块902,具体用于控制获取窗口焦点的进程进入激活状态;所述控制模块902,还用于在失去窗口焦点的进程满足预设条件的情况下,通过所述目标通信连接,控制所述失去窗口焦点的进程进入非激活状态;其中,进入非激活状态的进程会关闭部分功能,进入激活状态的进程会重新启用进程进入非激活状态时关闭的功能。
可选地,所述装置还包括,显示模块和资源管理模块;所述获取模块901,具体用于获取窗口隐藏消息;所述控制模块902,具体用于在第一进程所对应的窗口全部处于隐藏状态的情况下,通过所述目标通信连接,控制所述第一进程进入不可见运行状态;所述显示模块,用于停止渲染所述第一进程的窗口;所述资源管理模块,用于在所述第一进程中所有进程均处于不可见运行状态的情况下,降低第一进程组的资源优先级;其中,所述第一进程为:第一窗口所属的进程;所述第一窗口为:所述窗口隐藏消息指示的需要隐藏的窗口;所述第一进程组包括:所述第一进程,和/或,所述第一进程的子进程。
可选地,所述获取模块901,具体用于获取第二进程的挂起消息;所述获取模块901,还用于获取所述第二进程的窗口状态信息;所述控制模块902,具体用于在所述窗口状态信息指示所述第二进程所对应的窗口均处于隐藏状态的情况下,通过所述目标通信连接,向所述第二进程发送第一消息;所述第一消息用于通知所述第二进程在第一预设时间内保留目标数据;所述目标数据为所述第二进程恢复时所需的必要数据;所述通信模块,具体用于当所述第一预设时间结束后,通过所述目标通信连接,向所述第二进程发送SIGINT消息;所述控制模块902,具体用于控制所述第二进程进入挂起状态;所述控制模块902,具体用于在第二进程组中的所有进程处于不可见运行状态的情况下,控制所述第二进程组中的进程进入挂起状态;其中,所述第二进程组为所述第二进程所属的进程组。
可选地,所述获取模块901,具体用于获取所述第二进程的恢复消息;所述恢复消息用于指示所述第二进程从挂起状态进入正常运行状态;所述通信模块,还用于向所述第二进程发送SIGCONT消息;所述通信模块,还用于在所述第二进程处于正常运行状态的情况下,通过所述目标通信连接,向所述第二进程发送第二消息;所述控制模块902,具体用于控制所述第二进程基于所述目标数据恢复所述第二进程进入挂起状态前的运行状态;所述通信模块,还用于向窗口管理器发送第三消息,恢复所述第二进程对应的窗口。
可选地,所述获取模块901,具体用于获取第三进程的应用停止信息;所述通信模块,还用于在所述第三进程处于挂起状态的情况下,向所述第三进程发送SIGCONT消息;所述控制模块902,具体用于控制所述第三进程恢复运行状态;所述通信模块,还用于通过所述目标通信连接,向所述第三进程发送第四消息;所述第四消息用于指示所述第三进程在第二预设时间内完成停止前准备工作;所述通信模块,还用于当所述第二预设时间结束后,向所述第三进程发送SIGTERM消息;所述通信模块,还用于在所述第三进程终止超时的情况下,向所述第三进程发送SIGKILL消息;所述获取模块901,还用于获取所述目标控制群组内与所述第三进程相关联的第四进程的进程状态信息;所述资源管理模块,还用于基于所述第四进程的进程状态信息,按照预设回收策略回收所述第四进程所占用的资源。
本公开提供的Linux应用进程管理装置,通过目标应用的目标控制群组,获取该目标控制群组中每个进程的进程信息,并与之建立通信连接。之后,当系统获取到目标控制群组中目标应用的进程状态变更信息时,基于该进程状态变更信息,通过与目标进程建立的目标通信连接,向该目标进程发送控制信,控制目标进程执行与所述状态变更信息对应的操作,进而实现对目标应用的每个进程整个生命周期的管理。
图10示例了一种电子设备的实体结构示意图,如图10所示,该电子设备可以包括:处理器(processor)1010、通信接口(Communications Interface)1020、存储器(memory)1030和通信总线1040,其中,处理器1010,通信接口1020,存储器1030通过通信总线1040完成相互间的通信。处理器1010可以调用存储器1030中的逻辑指令,以执行Linux应用进程管理方法,该方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
此外,上述的存储器1030中的逻辑指令可以通过软件功能单元的形式实现并作为独 立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本公开的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本公开各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
另一方面,本公开还提供一种计算机程序产品,所述计算机程序产品包括存储在非暂态计算机可读存储介质上的计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,计算机能够执行上述各方法所提供的Linux应用进程管理方法,所述方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
另一方面,本公开还提供一种计算机程序,所述计算机程序包括程序指令,当所述程序指令被计算机执行时,计算机能够执行上述各方法所提供的Linux应用进程管理方法,所述方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
又一方面,本公开还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现以执行上述各提供的Linux应用进程管理方法,该方法包括:获取目标应用的进程状态变更信息;基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作;其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳 动的情况下,即可以理解并实施。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。
最后应说明的是:以上实施例仅用以说明本公开的技术方案,而非对其限制;尽管参照前述实施例对本公开进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本公开各实施例技术方案的精神和范围。

Claims (12)

  1. 一种Linux应用进程管理方法,其特征在于,包括:
    获取目标应用的进程状态变更信息;
    基于所述进程状态变更信息,通过与目标进程建立的目标通信连接,控制所述目标进程执行与所述状态变更信息对应的操作;
    其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
  2. 根据权利要求1所述的方法,其特征在于,所述获取目标应用的进程状态变更信息之前,所述方法还包括:
    获取所述目标应用的启动请求;
    响应于所述启动请求,创建目标应用进程;
    在所述目标应用进程创建成功的情况下,创建所述目标控制群组,将所述目标应用进程加入所述目标控制群组,并建立与所述目标应用进程的通信连接;
    基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息。
  3. 根据权利要求2所述的方法,其特征在于,所述基于所述目标应用进程的当前运行状态,记录所述目标应用进程的状态信息之后,所述方法还包括:
    获取所述目标应用进程的子进程创建成功的消息;
    建立与所述目标应用进程的子进程间的通信连接;
    将所述目标应用进程的子进程加入所述目标控制群组;
    基于所述目标应用进程的子进程的当前运行状态,记录所述目标应用进程的子进程的状态信息。
  4. 根据权利要求1至3中任一项所述的方法,其特征在于,所述获取目标应用的进程状态变更信息,包括:
    获取窗口焦点变更消息;
    所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:
    控制获取窗口焦点的进程进入激活状态,并在失去窗口焦点的进程满足预设条件的情况下,通过所述目标通信连接,控制所述失去窗口焦点的进程进入非激活状态;
    其中,进入非激活状态的进程会关闭部分功能,进入激活状态的进程会重新启用进程进入非激活状态时关闭的功能。
  5. 根据权利要求1至3中任一项所述的方法,其特征在于,所述获取目标应用的进程状态变更信息,包括:
    获取窗口隐藏消息;
    所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:
    在第一进程所对应的窗口全部处于隐藏状态的情况下,通过所述目标通信连接,控制所述第一进程进入不可见运行状态;
    停止渲染所述第一进程的窗口,并在所述第一进程中所有进程均处于不可见运行状态的情况下,降低第一进程组的资源优先级;
    其中,所述第一进程为:第一窗口所属的进程;所述第一窗口为:所述窗口隐藏消息指示的需要隐藏的窗口;所述第一进程组包括:所述第一进程,和/或,所述第一进程的子进程。
  6. 根据权利要求1至3中任一项所述的方法,其特征在于,所述获取目标应用的进程状态变更信息,包括:
    获取第二进程的挂起消息;所述挂起消息用于指示所述第二进程进入挂起状态;
    所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:
    获取所述第二进程的窗口状态信息;
    在所述窗口状态信息指示所述第二进程所对应的窗口均处于隐藏状态的情况下,通过所述目标通信连接,向所述第二进程发送第一消息;所述第一消息用于通知所述第二进程在第一预设时间内保留目标数据;所述目标数据为所述第二进程恢复时所需的必要数据;
    当所述第一预设时间结束后,向所述第二进程发送SIGINT消息,控制所述第二进程进入挂起状态;
    在第二进程组中的所有进程处于不可见运行状态的情况下,控制所述第二进程组中的进程进入挂起状态;
    其中,所述第二进程组为所述第二进程所属的进程组。
  7. 根据权利要求6所述的方法,其特征在于,所述获取目标应用的进程状态变更信息,包括:
    获取所述第二进程的恢复消息;所述恢复消息用于指示所述第二进程从挂起状态进入正常运行状态;
    所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:
    向所述第二进程发送SIGCONT消息;
    在所述第二进程处于正常运行状态的情况下,通过所述目标通信连接,向所述第二进程发送第二消息,控制所述第二进程基于所述目标数据恢复所述第二进程进入挂起状态前的运行状态;
    向窗口管理器发送第三消息,恢复所述第二进程对应的窗口。
  8. 根据权利要求1至3中任一项所述的方法,其特征在于,
    所述获取目标应用的进程状态变更信息,包括:所述获取目标应用的进程状态变更信息,包括:
    获取第三进程的应用停止信息;
    所述基于所述进程状态变更信息,通过与所述目标进程建立的目标通信连接,控制目标进程执行与所述状态变更信息对应的操作,包括:
    在所述第三进程处于挂起状态的情况下,向所述第三进程发送SIGCONT消息,控制所述第三进程恢复运行状态;
    通过所述目标通信连接,向所述第三进程发送第四消息;所述第四消息用于指示所述第三进程在第二预设时间内完成停止前准备工作;
    当所述第二预设时间结束后,向所述第三进程发送SIGTERM消息;
    在所述第三进程终止超时的情况下,向所述第三进程发送SIGKILL消息;
    获取所述目标控制群组内与所述第三进程相关联的第四进程的进程状态信息;
    基于所述第四进程的进程状态信息,按照预设回收策略回收所述第四进程所占用的资源。
  9. 一种Linux应用进程管理装置,其特征在于,所述装置包括:
    获取模块,用于获取目标应用的进程状态变更信息;
    控制模块,用于基于所述获取模块获取的进程状态变更信息,通过与目标进程建立的目标通信连接,控制所述目标进程执行与所述状态变更信息对应的操作;
    其中,所述目标进程为所述目标应用的目标控制群组中的进程;所述目标通信连接为所述目标进程创建时与所述目标进程建立的通信连接。
  10. 一种非暂态计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至8中任一项所述Linux应用进程管理方法的 步骤。
  11. 一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现如权利要求1至8中任一项所述Linux应用进程管理方法的步骤。
  12. 一种计算机程序,所述计算机程序被处理器执行时实现如权利要求1至8中任一项所述Linux应用进程管理方法的步骤。
PCT/CN2022/107182 2021-11-17 2022-07-21 Linux应用进程管理方法及装置 WO2023087765A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111358725.4A CN113791888A (zh) 2021-11-17 2021-11-17 Linux应用进程管理方法及装置
CN202111358725.4 2021-11-17

Publications (1)

Publication Number Publication Date
WO2023087765A1 true WO2023087765A1 (zh) 2023-05-25

Family

ID=78877361

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/107182 WO2023087765A1 (zh) 2021-11-17 2022-07-21 Linux应用进程管理方法及装置

Country Status (2)

Country Link
CN (1) CN113791888A (zh)
WO (1) WO2023087765A1 (zh)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113791888A (zh) * 2021-11-17 2021-12-14 北京鲸鲮信息系统技术有限公司 Linux应用进程管理方法及装置
CN116055789B (zh) * 2023-03-24 2023-08-11 杭州星犀科技有限公司 基于安卓系统的直播画面放大方法、系统、设备和介质

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5867160A (en) * 1996-10-31 1999-02-02 International Business Machines Corporation System and method for task prioritization in computerized graphic interface environments
US20150347179A1 (en) * 2014-06-01 2015-12-03 Apple Inc. Priority-based managing of window processes in a browser application
CN105573777A (zh) * 2014-11-11 2016-05-11 阿里巴巴集团控股有限公司 应用中服务的控制方法及装置
CN107807847A (zh) * 2016-09-09 2018-03-16 华为技术有限公司 应用进程的管理方法和终端设备
CN111176801A (zh) * 2019-07-17 2020-05-19 腾讯科技(深圳)有限公司 一种多进程管理方法、装置、设备及存储介质
CN111400081A (zh) * 2020-03-24 2020-07-10 恒生电子股份有限公司 进程的守护方法、装置、电子设备和计算机存储介质
CN113791888A (zh) * 2021-11-17 2021-12-14 北京鲸鲮信息系统技术有限公司 Linux应用进程管理方法及装置

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7216346B2 (en) * 2002-12-31 2007-05-08 International Business Machines Corporation Method and apparatus for managing thread execution in a multithread application
GB2526088B (en) * 2014-05-12 2016-03-30 Sony Comp Entertainment Europe Apparatus and method of data capture
CN110955514A (zh) * 2019-10-09 2020-04-03 烽火通信科技股份有限公司 提高Linux业务进程利用率的方法、系统及计算机可读介质
CN111737060A (zh) * 2020-08-07 2020-10-02 北京金山云网络技术有限公司 处理组件异常的方法、装置及电子设备
CN112068876A (zh) * 2020-08-14 2020-12-11 北京达佳互联信息技术有限公司 一种进程管理方法、装置和系统

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5867160A (en) * 1996-10-31 1999-02-02 International Business Machines Corporation System and method for task prioritization in computerized graphic interface environments
US20150347179A1 (en) * 2014-06-01 2015-12-03 Apple Inc. Priority-based managing of window processes in a browser application
CN105573777A (zh) * 2014-11-11 2016-05-11 阿里巴巴集团控股有限公司 应用中服务的控制方法及装置
CN107807847A (zh) * 2016-09-09 2018-03-16 华为技术有限公司 应用进程的管理方法和终端设备
CN111176801A (zh) * 2019-07-17 2020-05-19 腾讯科技(深圳)有限公司 一种多进程管理方法、装置、设备及存储介质
CN111400081A (zh) * 2020-03-24 2020-07-10 恒生电子股份有限公司 进程的守护方法、装置、电子设备和计算机存储介质
CN113791888A (zh) * 2021-11-17 2021-12-14 北京鲸鲮信息系统技术有限公司 Linux应用进程管理方法及装置

Also Published As

Publication number Publication date
CN113791888A (zh) 2021-12-14

Similar Documents

Publication Publication Date Title
WO2023087765A1 (zh) Linux应用进程管理方法及装置
WO2022001900A1 (zh) 信息发送方法、装置和电子设备
EP3547715B1 (en) Method and apparatus for reducing continuous-wakeup delay of bluetooth loudspeaker, and bluetooth loudspeaker
US7249024B2 (en) Resource saving preemption
JP5960262B2 (ja) 接続型スタンバイのためのプロセスの一時停止及び/又は制限
EP2815328B1 (en) Power efficient brokered communication supporting notification blocking
JP5487951B2 (ja) 運用管理プログラム、運用管理装置および運用管理方法
CN102591668B (zh) 对弹性计算云系统升级的装置、方法及系统
JP2006209774A (ja) コンテキストアウェアネスプラットフォームのためのシステムおよび方法
TW201241640A (en) Dormant background applications on mobile devices
KR20190018038A (ko) 메모리 상태에 대한 응답으로 애플리케이션 종료
CN110769048B (zh) 本地与远程虚拟桌面的无缝衔接方法及系统
EP3209005B1 (en) Task processing device, intelligent apparatus, task processing method and baseband processor
CN112835688A (zh) 分布式事务处理方法、设备及存储介质
JP2014522061A (ja) 接続型スタンバイのためのプロセスの一時停止及び/又は制限
US20240176678A1 (en) Method, apparatus, electronic device and storage medium for application state synchronization
JP2014523059A (ja) 接続型スタンバイのためのプロセスの一時停止及び/又は制限
WO2017014919A1 (en) Background task management
US20120311490A1 (en) Methods for launching applications with efficient user impression
US10606632B2 (en) Preventing interruption during virtual machine reboot
JP2004523812A (ja) 効率的なタイマ管理システム
JPH0628193A (ja) オブジェクト指向ソフトウエアシステムにおける方法及びシステム
US11893225B2 (en) Host to client drag-and-drop operation
US20160306531A1 (en) Dynamic Launch Behavior Based on Context Information
CN112596925B (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: 22894308

Country of ref document: EP

Kind code of ref document: A1