CN118277043A - Application process management method, system, device, storage medium and terminal equipment - Google Patents
Application process management method, system, device, storage medium and terminal equipment Download PDFInfo
- Publication number
- CN118277043A CN118277043A CN202211713992.3A CN202211713992A CN118277043A CN 118277043 A CN118277043 A CN 118277043A CN 202211713992 A CN202211713992 A CN 202211713992A CN 118277043 A CN118277043 A CN 118277043A
- Authority
- CN
- China
- Prior art keywords
- process group
- group
- running condition
- file descriptor
- killing
- Prior art date
- Legal status (The legal status 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 status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 325
- 238000007726 management method Methods 0.000 title abstract description 28
- 238000012544 monitoring process Methods 0.000 claims description 9
- 230000006870 function Effects 0.000 description 17
- 239000011230 binding agent Substances 0.000 description 14
- 238000004590 computer program Methods 0.000 description 6
- 230000000694 effects Effects 0.000 description 3
- 238000010586 diagram Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000006467 substitution reaction Methods 0.000 description 2
- 238000013459 approach Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004891 communication Methods 0.000 description 1
- 230000007423 decrease Effects 0.000 description 1
- 230000002085 persistent effect Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention relates to the technical field of application process management, in particular to a management method, a system, a device, a storage medium and terminal equipment of an application process, and aims to solve the problem of how to effectively release system resources occupied by a ghost program when a main process is accidentally ended. For this purpose, in the present invention, when a process group is created, a pid file descriptor is created for the process group, the running condition of the main process of the process group is determined according to the pid file descriptor, when the running condition of the main process is the end of the process, a command for killing the process group is executed, and after all the processes of the process group are ended, the device file of the process group is closed. Judging the running condition of the main process through the pid file descriptor, when the main process is the process end, executing the command of killing the process group to end all the processes of the process group, closing the device file after all the processes of the process group are ended, and when the device file is closed, executing the death callback function correctly, thereby effectively releasing the system resources occupied by the process group.
Description
Technical Field
The invention relates to the technical field of application process management, and particularly provides a management method, a system, a device, a storage medium and terminal equipment for an application process.
Background
In the existing android system version, when the main process of the application is created, the system actively sets a binder died callback function to the binder driver. When the process closes/dev/binder file, the binder driver then calls the callback function to notify the frame layer, that is ACTIVITYMANAGERSERVICE (abbreviated as AMS) in the system_server process, and the AMS deletes the system resource applied by the process in the callback function and ends all the sub-processes thereof.
However, such a method cannot cope with the situation that the main process ends accidentally, such as crash or directly calls system. Exit (), and at this time, the sub-process does not end, and the/dev/binder file is not closed, so that the binder died callback function of the AMS is not executed. These sub-processes will become ghost processes that are not hosted by the android system, and if ghost processes are not handled, the surviving ghost processes will continue to occupy system resources.
Accordingly, there is a need in the art for a new ghost process approach to solve the above-described problems.
Disclosure of Invention
The present invention has been made to overcome the above-mentioned drawbacks, and provides a solution or at least partially solves the problem of how to effectively release the system resources occupied by the ghost procedure when the main process ends accidentally.
In a first aspect, the present invention provides a method for managing an application process, the method including:
when a process group is created, creating a pid file descriptor of the process group for the process group;
Judging the running condition of a main process of the process group according to the pid file descriptor;
Executing a process group killing command when the running condition of the main process is that the process is finished;
And when the killing process group command finishes all the processes of the process group, closing the device file of the process group so as to realize the execution of a death callback function and release the system resources occupied by the process group.
In one technical solution of the above application process management method, the step of "determining the running condition of the main process of the process group according to the pid file descriptor" includes:
monitoring the running condition of the main process of the process group through the pid file descriptor;
and judging the running condition of the main process according to the monitoring result.
In one technical solution of the above application process management method, the step of "monitoring, through the pid file descriptor, the running condition of the main process of the process group" includes:
Adding the pid file descriptor to a message queue;
And controlling the message queue to monitor the running condition of the main process of the process group through a linux epoll mechanism.
In one technical scheme of the above application process management method, the step of "judging the running condition of the main process according to the monitoring result" includes:
And when the message queue receives an event_input EVENT, judging that the running condition of the main process is running ending.
In one technical solution of the above application process management method, the step of "executing the process killing group command" includes:
and controlling the AMS to send out the command of the killing process group so as to finish the sub-process of the process group.
In one technical solution of the above application process management method, the step of creating the pid file descriptor of the process group for the process group includes:
and applying the pid file descriptors of the process group to the linux kernel in the AMS to realize the creation of the pid file descriptors.
In a second aspect, the present invention provides a management system for an application process, the system comprising:
A pid file descriptor creation module configured to create a pid file descriptor of a process group for the process group when the process group is created;
The main process running condition judging module is configured to judge the running condition of the main process of the process group according to the pid file descriptor;
The killing process group module is configured to execute a killing process group command when the running condition of the main process is the process end;
And the system resource release module is configured to close the device file of the process group when the killing process group command finishes all the processes of the process group so as to realize the execution of a death callback function and release the system resources occupied by the process group.
In a third aspect, a control device is provided, the control device comprising a processor and a storage device, the storage device being adapted to store a plurality of program codes, the program codes being adapted to be loaded and run by the processor to perform the method for managing an application process according to any one of the above-mentioned embodiments of the method for managing an application process.
In a fourth aspect, there is provided a computer readable storage medium having stored therein a plurality of program codes adapted to be loaded and executed by a processor to perform the method for managing an application process according to any one of the above-mentioned aspects of the method for managing an application process.
In a fifth aspect, a terminal device is provided, where the terminal device includes an application process management system according to an application process management system technical scheme or a control device according to a control device technical scheme.
One or more of the above technical solutions of the present invention at least has one or more of the following
The beneficial effects are that:
In the technical scheme of implementing the invention, when the process group is created, a pid file descriptor is created for the process group, the running condition of a main process of the process group is judged according to the pid file descriptor, when the running condition of the main process is the end of the process, a command for killing the process group is executed, and after all the processes of the process group are ended, the device file of the process group is closed. Through the configuration mode, the running condition of the main process is judged through the pid file descriptor, when the main process is the process end, the executing of the process group killing command ends all the processes of the process group, after all the processes of the process group are ended, the device file can be closed, and when the device file is closed, the death callback function can be correctly executed, so that the system resources occupied by the process group can be effectively released.
Drawings
The present disclosure will become more readily understood with reference to the accompanying drawings. As will be readily appreciated by those skilled in the art: the drawings are for illustrative purposes only and are not intended to limit the scope of the present invention. Wherein:
FIG. 1 is a flow chart illustrating the main steps of a method for managing an application process according to one embodiment of the present invention;
FIG. 2 is a flow chart illustrating the main steps of a method for managing an application process according to an embodiment of the present invention;
Fig. 3 is a schematic block diagram of the main structure of a management system of an application process according to an embodiment of the present invention.
Detailed Description
Some embodiments of the invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are merely for explaining the technical principles of the present invention, and are not intended to limit the scope of the present invention.
In the description of the present invention, a "module," "processor" may include hardware, software, or a combination of both. A module may comprise hardware circuitry, various suitable sensors, communication ports, memory, or software components, such as program code, or a combination of software and hardware. The processor may be a central processor, a microprocessor, an image processor, a digital signal processor, or any other suitable processor. The processor has data and/or signal processing functions. The processor may be implemented in software, hardware, or a combination of both. Non-transitory computer readable storage media include any suitable medium that can store program code, such as magnetic disks, hard disks, optical disks, flash memory, read-only memory, random access memory, and the like. The term "a and/or B" means all possible combinations of a and B, such as a alone, B alone or a and B. The term "at least one A or B" or "at least one of A and B" has a meaning similar to "A and/or B" and may include A alone, B alone or A and B. The singular forms "a", "an" and "the" include plural referents.
Referring to fig. 1, fig. 1 is a schematic flow chart of main steps of a management method of an application process according to an embodiment of the present invention. As shown in fig. 1, the method for managing an application process in the embodiment of the present invention mainly includes the following steps S101 to S104.
Step S101: when a process group is created, pid (Process ID) file descriptors of the process group are created for the process group.
In this embodiment, when a process group is created, a pid file descriptor for the process group may be created for the process group (pidfd).
In one embodiment, when a process group is created, the pid file of the process group may be acquired first and a pid file descriptor may be created based on the pid file.
In one embodiment, the pid file descriptor of the process group may be applied to the linux kernel in the AMS to enable the creation of the pid file descriptor.
Step S102: and judging the running condition of the main process of the process group according to the pid file descriptor.
In this embodiment, the running condition of the process group may be determined according to the pid file descriptor.
In one embodiment, the operating conditions may include the process being run and the process ending, which may include normal running ending and unexpected running ending.
Step S103: and when the running condition of the main process is that the process is finished, executing the process killing group command.
In this embodiment, if the running condition of the main process is that the process ends, the process group killing instruction may be executed.
In one embodiment, when it is determined that the running condition of the main process is unexpected, the process group killing instruction may be executed to end the sub-process in the process group. In the case that the main process accidentally runs to end, such as crash or directly calls system. Exit (), the sub-processes will not end, so that these sub-processes become ghost processes, and the/dev/binder file will not be closed, so that the binder died callback function of AMS will not be executed, and the system resources occupied by ghost processes cannot be released.
In one embodiment, control AMS (ActivityManagerService) may actively issue a kill process group instruction to effect ending of a sub-process of the process group.
Step S104: and when the killing process group command finishes all the processes of the process group, closing the device file of the process group to realize the execution of the death callback function and release the system resources occupied by the process group.
In this embodiment, when all processes of the process group are finished, the device file of the process group may be closed, so that the death callback function may be executed correctly, thereby releasing the system resource occupied by the process group.
In one embodiment, the device file is a/dev/binder file.
In one embodiment, the process group shutdown/dev/binder file may be actively closed for the process group by the linux kernel.
In one embodiment, the callbacks may be binder died by death callback functions.
Based on the above steps S101 to S104, in the embodiment of the present invention, when the process group is created, a pid file descriptor is created for the process group, and according to the pid file descriptor, the running condition of the main process of the process group is determined, when the running condition of the main process is the end of the process, a command for killing the process group is executed, and after all the processes of the process group are ended, the device file of the process group is closed. Through the configuration mode, the embodiment of the invention judges the running condition of the main process through the pid file descriptor, when the main process is the process end, the executing of the process group killing command ends all the processes of the process group, after all the processes of the process group are ended, the device file can be closed, and when the device file is closed, the death callback function can be correctly executed, so that the system resources occupied by the process group can be effectively released.
Step S102 is further described below.
In one implementation of the embodiment of the present invention, step S102 may further include the following steps S1021 and S1022:
step S1021: and monitoring the running condition of the main process of the process group through the pid file descriptor.
In the present embodiment, step S1021 may further include the following steps S10211 and S10212:
Step S10211: the pid file descriptor is added to the message queue (MessageQueue).
Step S10212: the control message queue monitors the running condition of the main process of the process group through a linux epoll mechanism. The epoll mechanism has the characteristic of more flexibility, has no descriptor limit, manages a plurality of descriptors by using one file descriptor, and stores events of the file descriptors of the user relationship into an event table of the kernel.
In this embodiment, messageQueue may be used to monitor pidfd of the process group after the process is created, and enter an asynchronous monitor state. The message queue may be a common message queue such as RabbitMQ, rocketMQ, activeMQ, kafka, zeroMQ, metaMq.
Step S1022: and judging the running condition of the main process according to the monitoring result.
In this embodiment, step S1022 may be further configured to:
When the message queue receives the event_input EVENT, the running condition of the main process is judged to be running end.
In this embodiment, if the message queue receives the event_input EVENT, it indicates pidfd that the corresponding pid has finished, and it may be determined that the running condition of the main process is the running end.
In one embodiment, referring to fig. 2, fig. 2 is a schematic flow chart of main steps of a method for managing an application process according to an embodiment of the present invention. As shown in fig. 2, the management method of the application process may include the following steps S201 to S214:
Step S201: and (5) creating a process.
In this embodiment, each process in the process group may be created first.
Step S202: the process pid is acquired.
In this embodiment, the pid file of the process group may be acquired.
Step S203: process pidfd is created.
In this embodiment, pidfd (pid file descriptor) may be created for a group of processes.
Step S204: pidfd was added to MessageQueue.
In this embodiment pidfd can be added to MessageQueue (message queue).
Step S205: epoll listens pidfd.
In this embodiment, pidfd may be monitored by the epoll mechanism of linux.
Step S206: asynchronous listening.
In this embodiment, persistent asynchronous listening to pidfd may be implemented by epoll.
Step S207: expoll monitor the end of the process.
In this embodiment, once expoll receives the event_input EVENT, it indicates that the pid corresponding to pidfd has completely ended, i.e., expoll monitors the end of the process.
Step S208: and obtaining the finished pidfd.
In this embodiment, pidfd of the completed process group may be acquired.
Step S209: the AMS performs a kill process group operation.
In this embodiment, when it is determined that the pid is completely ended, the killing process group operation may be performed by the AMS.
Step S210: asynchronous waiting.
In this embodiment, an asynchronous wait state may be entered after the AMS performs the group killing operation.
Step S211: all processes end.
In this embodiment, it may be determined whether all processes in the process group are finished, and after all processes are finished, the linux kernel may be turned off/dev/binder for the process group.
Step S212: the death callback function is executed.
In this embodiment, after the/dev/binder is closed, the binder driver will then actively call back the death callback function of the process set by the AMS. As long as the death callback function of the AMS is executed correctly, the system resources can be released correctly.
Step S213: and releasing the resource.
In this embodiment, the system resource process occupied by the process group can be correctly released.
It should be noted that, although the foregoing embodiments describe the steps in a specific order, it will be understood by those skilled in the art that, in order to achieve the effects of the present invention, the steps are not necessarily performed in such an order, and may be performed simultaneously (in parallel) or in other orders, and these variations are within the scope of the present invention.
Furthermore, the invention also provides a management system of the application process.
Referring to fig. 3, fig. 3 is a main block diagram of a management system of an application process according to an embodiment of the present invention. As shown in fig. 3, the management system of the application process in the embodiment of the present invention may include a pid file descriptor creation module, a main process running condition judgment module, a killing process group module, and a system resource release module. In this embodiment, the pid file descriptor creation module may be configured to create a pid file descriptor of a process group for a process group when the process group is created. The main process running condition judging module may be configured to judge the running condition of the main process of the process group according to the pid file descriptor. The kill process group module may be configured to execute the kill process group command when the running condition of the main process is the end of the process. The system resource release module may be configured to close the device file of the process group when the killing process group command ends all processes of the process group, so as to implement the execution of the death callback function, and release the system resource occupied by the process group.
The technical principles of the two embodiments, the technical problems to be solved, and the technical effects to be produced are similar, and those skilled in the art can clearly understand that, for convenience and brevity of description, the specific working process and related description of the application process management system may refer to the description of the embodiment of the application process management method, which is not repeated herein.
It will be appreciated by those skilled in the art that the present invention may implement all or part of the above-described methods according to the above-described embodiments, or may be implemented by means of a computer program for instructing relevant hardware, where the computer program may be stored in a computer readable storage medium, and where the computer program may implement the steps of the above-described embodiments of the method when executed by a processor. Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable storage medium may include: any entity or device, medium, usb disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory, random access memory, electrical carrier wave signals, telecommunications signals, software distribution media, and the like capable of carrying the computer program code. It should be noted that the computer readable storage medium may include content that is subject to appropriate increases and decreases as required by jurisdictions and by jurisdictions in which such computer readable storage medium does not include electrical carrier signals and telecommunications signals.
Further, the invention also provides a control device. In one control device embodiment according to the present invention, the control device includes a processor and a storage device, the storage device may be configured to store a program for executing the management method of the application process of the above-described method embodiment, and the processor may be configured to execute the program in the storage device, including, but not limited to, the program for executing the management method of the application process of the above-described method embodiment. For convenience of explanation, only those portions of the embodiments of the present invention that are relevant to the embodiments of the present invention are shown, and specific technical details are not disclosed, please refer to the method portions of the embodiments of the present invention. The control device may be a control device formed of various electronic devices.
Further, the invention also provides a computer readable storage medium. In one embodiment of the computer-readable storage medium according to the present invention, the computer-readable storage medium may be configured to store a program for executing the management method of the application process of the above-described method embodiment, which may be loaded and executed by a processor to implement the management method of the application process described above. For convenience of explanation, only those portions of the embodiments of the present invention that are relevant to the embodiments of the present invention are shown, and specific technical details are not disclosed, please refer to the method portions of the embodiments of the present invention. The computer readable storage medium may be a storage device including various electronic devices, and optionally, the computer readable storage medium in the embodiments of the present invention is a non-transitory computer readable storage medium.
The invention further provides terminal equipment. In one terminal device embodiment according to the invention, the terminal device may comprise a management system of the application process in a management system embodiment of the application process. In a further embodiment of the terminal device according to the invention, the terminal device may comprise control means in the embodiment of the control means.
Further, it should be understood that, since the respective modules are merely set to illustrate the functional units of the apparatus of the present invention, the physical devices corresponding to the modules may be the processor itself, or a part of software in the processor, a part of hardware, or a part of a combination of software and hardware. Accordingly, the number of individual modules in the figures is merely illustrative.
Those skilled in the art will appreciate that the various modules in the apparatus may be adaptively split or combined. Such splitting or combining of specific modules does not cause the technical solution to deviate from the principle of the present invention, and therefore, the technical solution after splitting or combining falls within the protection scope of the present invention.
Thus far, the technical solution of the present invention has been described in connection with the preferred embodiments shown in the drawings, but it is easily understood by those skilled in the art that the scope of protection of the present invention is not limited to these specific embodiments. Equivalent modifications and substitutions for related technical features may be made by those skilled in the art without departing from the principles of the present invention, and such modifications and substitutions will fall within the scope of the present invention.
Claims (10)
1. A method for managing an application process, the method comprising:
when a process group is created, creating a pid file descriptor of the process group for the process group;
Judging the running condition of a main process of the process group according to the pid file descriptor;
Executing a process group killing command when the running condition of the main process is that the process is finished;
And when the killing process group command finishes all the processes of the process group, closing the device file of the process group so as to realize the execution of a death callback function and release the system resources occupied by the process group.
2. The method according to claim 1, wherein the step of judging the running condition of the main process of the process group based on the pid file descriptor includes:
monitoring the running condition of the main process of the process group through the pid file descriptor;
and judging the running condition of the main process according to the monitoring result.
3. The method for managing an application process according to claim 2, wherein the step of "listening to the running condition of the main process of the process group through the pid file descriptor" comprises:
Adding the pid file descriptor to a message queue;
And controlling the message queue to monitor the running condition of the main process of the process group through a linuxepoll mechanism.
4. The method for managing an application process according to claim 3, wherein the step of judging the running condition of the main process based on the monitoring result comprises:
And when the message queue receives an event_input EVENT, judging that the running condition of the main process is running ending.
5. The method of claim 1, wherein the step of executing the group of processes killing command includes:
and controlling the AMS to send out the command of the killing process group so as to finish the sub-process of the process group.
6. The method of claim 1, wherein creating a pid file descriptor for the process group comprises:
and applying the pid file descriptors of the process group to the linux kernel in the AMS to realize the creation of the pid file descriptors.
7. A system for managing application processes, the system comprising:
A pid file descriptor creation module configured to create a pid file descriptor of a process group for the process group when the process group is created;
The main process running condition judging module is configured to judge the running condition of the main process of the process group according to the pid file descriptor;
The killing process group module is configured to execute a killing process group command when the running condition of the main process is the process end;
And the system resource release module is configured to close the device file of the process group when the killing process group command finishes all the processes of the process group so as to realize the execution of a death callback function and release the system resources occupied by the process group.
8. A control device comprising a processor and a storage device, said storage device being adapted to store a plurality of program codes, characterized in that said program codes are adapted to be loaded and run by said processor to perform the method of managing an application process according to any one of claims 1 to 6.
9. A computer readable storage medium, in which a plurality of program codes are stored, characterized in that the program codes are adapted to be loaded and run by a processor to perform the method of managing an application process according to any one of claims 1 to 6.
10. A terminal device, characterized in that it comprises a management system for application processes according to claim 7 or a control device according to claim 8.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211713992.3A CN118277043A (en) | 2022-12-29 | 2022-12-29 | Application process management method, system, device, storage medium and terminal equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211713992.3A CN118277043A (en) | 2022-12-29 | 2022-12-29 | Application process management method, system, device, storage medium and terminal equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118277043A true CN118277043A (en) | 2024-07-02 |
Family
ID=91648941
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211713992.3A Pending CN118277043A (en) | 2022-12-29 | 2022-12-29 | Application process management method, system, device, storage medium and terminal equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118277043A (en) |
-
2022
- 2022-12-29 CN CN202211713992.3A patent/CN118277043A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110737534B (en) | Task processing method and device and server | |
CN110765023B (en) | Distributed system testing method and system based on chaos experiment | |
CN106557470B (en) | Data extraction method and device | |
CN107025135B (en) | Application process management method, device and medium in Docker container | |
CN110362394B (en) | Task processing method and device, storage medium and electronic device | |
CN108563472B (en) | Service plug-in loading method and device based on multi-open application | |
CN107741891B (en) | Object reconstruction method, medium, device and computing equipment | |
CN107908957B (en) | Safe operation management method and system of intelligent terminal | |
CN108205503B (en) | Hardware drive compatible method and terminal | |
CN118277043A (en) | Application process management method, system, device, storage medium and terminal equipment | |
US9658894B2 (en) | Automatically and dynamically reclaiming resources during virtual machine decommission | |
CN117149365A (en) | Task processing method, device, electronic equipment and storage medium | |
CN112130900B (en) | User information management method, system, equipment and medium for BMC | |
CN114816482A (en) | Method and device for upgrading block storage service, computer equipment and storage medium | |
CN113220477A (en) | Shear plate reading control method and device, electronic equipment and storage medium | |
CN112540886A (en) | CPU load value detection method and device | |
CN110149356A (en) | Method and device is uniformly processed in a kind of network request abnormality | |
CN110716972A (en) | Method and device for processing error of high-frequency calling external interface | |
CN112506592A (en) | Method, device, equipment and storage medium for determining page loading duration | |
CN114268665B (en) | Micro service system release method, device, equipment and readable storage medium | |
CN116126232A (en) | Business operation control method, device, electronic equipment and storage medium | |
CN113546408B (en) | Game scene processing method, device, equipment, medium and program product | |
CN117938797A (en) | Message pushing method and device, electronic equipment and storage medium | |
CN117234600A (en) | Android system quick starting method, system and equipment | |
CN101442549B (en) | Method and apparatus for controlling concurrence error |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |