IPC communication method and device among multiple processes, computer equipment and medium
By creating a middleware container instance for each two processes and loading the middleware, the problem that the interaction management code cannot be reused during inter-process communication is solved, the reuse of the interaction management code for inter-process communication is realized, and the complexity of the process code is reduced. .
Patent Information
- Application Number
- CN202310413386.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-17
- Publication Date
- 2024-10-22
AI Technical Summary
In the existing technology, the printing log and communication timeout monitoring function codes during inter-process communication cannot be reused, resulting in strong intrusion into the original business of each process and the process code becoming bloated.
By creating middleware container instances for each two processes and loading middleware on the communication channel, interaction management between processes is achieved and modifications to the original business code are avoided.
It realizes the reuse of interactive management code for inter-process communication, reduces the complexity of process code, and avoids strong intrusion into the original business.
Smart Images

Figure CN118819880A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of inter-process communication, and in particular to an IPC communication method, apparatus, computer device and computer-readable storage medium between multiple processes. Background Art
[0002] Electron is a cross-platform desktop application framework that uses JavaScript, HTML, and CSS to load applications for multiple operating systems. Electron can start multiple processes at the same time during operation. A process is an instance of a program running on a computer, with independent memory space and execution environment. Different processes are used to implement different business functions. Different processes can communicate with each other to perform operations such as data exchange and resource sharing. For example, process 1 can send messages to process 2, and process 2 can reply to process 1. The IPC communication mechanism refers to a way to implement inter-process communication. The inter-process communication mechanism is an important function in the operating system, which allows different processes to exchange data, share resources, and perform other operations. During the IPC communication between two processes, each communication channel needs to be managed interactively, such as printing logs or monitoring communication timeouts.
[0003] Generally speaking, the functional codes for interactive management such as printing logs and communication timeout monitoring cannot be reused. It is necessary to write corresponding functional codes and add them to each process to implement the corresponding functions, which causes a strong intrusion on the original business of each process and easily makes the original business code of the process bloated. Summary of the invention
[0004] In order to overcome the problems existing in the related art, the present application provides an IPC communication method, device, computer equipment and computer storage medium between multiple processes. The IPC communication method between multiple processes enables each process to share the same container class code to implement interactive management during inter-process communication, and the interactive management business codes between different processes are reused without causing strong intrusion on the original business, which helps to reduce the complexity of the process code.
[0005] According to a first aspect of an embodiment of the present application, an IPC communication method between multiple processes is provided. The IPC communication method is applied to a multi-process application. The multi-process application starts multiple processes at runtime. IPC communication is implemented between two processes with information interaction through a communication channel. The IPC communication method includes the following steps:
[0006] A middleware container instance is created for each two processes that have information interaction, and several middlewares are loaded in the middleware container instance. Each two processes that have information interaction perform information interaction through each middleware in the middleware container instance.
[0007] On each communication channel, the sending process sends a first interactive message to the receiving process through each middleware of the middleware container, and the receiving process replies to the sending process with a second interactive message through each middleware of the middleware container, where the second interactive message is an interactive message used to reply to the first interactive message sent by the sending process;
[0008] The interaction between the two processes is managed through various middlewares, and the corresponding data values are returned to the preset process.
[0009] According to a second aspect of an embodiment of the present application, there is provided an IPC communication device between multiple processes, including:
[0010] An instance creation module is used to create a middleware container instance for each two processes that have information interaction, load several middlewares in the middleware container instance, and each two processes that have information interaction perform information interaction through each middleware in the middleware container instance;
[0011] An interaction module, configured to enable a sending process to send a first interaction message to a receiving process through each middleware of the middleware container at both ends of each communication channel, and the receiving process to reply a second interaction message to the sending process through each middleware of the middleware container, wherein the second interaction message is an interaction message used to reply to the sending process;
[0012] The interaction management module is used to manage the interaction process between two processes through various middlewares on each communication channel, and form corresponding data values and return them to the corresponding processes.
[0013] According to a third aspect of an embodiment of the present application, a computer device is provided, comprising at least one processor and at least one memory; the memory is electrically connected to the processor; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the IPC communication method between multiple processes disclosed in the above embodiment.
[0014] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. The computer program is suitable for being loaded by a processor and executing the IPC communication method between multiple processes disclosed in the above embodiment.
[0015] The technical solution of the above-mentioned embodiment of the present application creates a middleware container instance for every two processes that have information interaction, and loads several middlewares in the middleware instance on each communication channel to manage the interaction process between the two processes, so that each process can share the same container class code to realize the interaction management in the process of inter-process communication, and the interaction management business code between different processes is reused, and will not cause strong intrusion to the original business, which helps to reduce the complexity of the process code.
[0016] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application.
[0017] For better understanding and implementation, the present application is described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 A schematic diagram of the interaction process between two processes in the related art;
[0019] Figure 2 This is a flow chart of an IPC communication method between multiple processes shown in Example 1 of the present application;
[0020] Figure 3 This is a schematic diagram of the interaction process between two processes shown in Example 1 of the present application;
[0021] Figure 4 This is a schematic diagram of the arrangement of middleware between two processes shown in the first embodiment of the present application;
[0022] Figure 5 This is a specific example diagram of the middleware between two processes shown in the first embodiment of the present application;
[0023] Figure 6 This is a structural block diagram of an IPC communication device between multiple processes shown in Embodiment 2 of the present application;
[0024] Figure 7 This is a structural block diagram of a computer device shown in Example 3 of the present application. DETAILED DESCRIPTION
[0025] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0026] The terms used in this application are for the purpose of describing specific embodiments only and are not intended to limit this application. The singular forms of "a", "said" and "the" used in this application and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0027] It should be understood that, although the terms first, second, third, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" / "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determination".
[0028] like Figure 1 As shown, Figure 1 It is a schematic diagram of the interaction process between two processes in the related technology.
[0029] In the related art, multiple processes running on the same application may include process 1 and process 2, and process 1 and process 2 communicate and exchange information based on an IPC communication channel. When process 1 sends a parameter to process 2, it is necessary to add a code for implementing log printing in the source code of process 1 in order to implement the interactive management function of printing logs. If timeout processing is to be implemented, it is necessary to add a code for implementing timeout processing in the source code of process 1 in order to implement the interactive management function of timeout management. Since the code for implementing the interactive management function cannot be reused, it will cause a strong invasion to the original business of each process, which is easy to make the original business code of the process bloated.
[0030] In response to the above problems, the first aspect of the embodiments of the present application discloses an IPC communication method between multiple processes, which enables each process to share the same container class code to implement interactive management during inter-process communication. The interactive management business codes between different processes are reused without causing strong intrusion on the original business, which helps to reduce the complexity of the process code.
[0031] In this embodiment, the IPC communication method between multiple processes is applied to a multi-process application. The application can be applicable to different operating systems. The application runs on smart devices such as computers. The smart devices can be any form of computers, interactive tablets, conference tablets, smart phones and other devices.
[0032] The IPC communication method between multiple processes is applied to multi-process applications. The multi-process application starts multiple processes at runtime, and IPC communication is implemented between two processes with information interaction through corresponding IPC communication channels.
[0033] The multi-process application can run in various operating systems, such as Windows operating system, Linux operating system, or IOS operating system. The present embodiment does not limit the operating system. The operating system can be installed on any form of computer, interactive tablet, conference tablet, or smart phone.
[0034] like Figure 2 and Figure 3 As shown, the IPC communication method includes the following steps:
[0035] S1: Create a middleware container instance for each two processes that have information interaction, load several middlewares in the middleware container instance, and each two processes that have information interaction perform information interaction through each middleware in the middleware container instance;
[0036] S2: On each communication channel, the sending process sends a first interactive message to the receiving process through each middleware of the middleware container, and the receiving process replies to the sending process with a second interactive message through each middleware of the middleware container, where the second interactive message is an interactive message used to reply to the first interactive message sent by the sending process;
[0037] S3: The interaction between the two processes is managed through various middlewares, and corresponding data values are formed and returned to the preset process.
[0038] The technical solution of the above-mentioned embodiment of the present application creates a middleware container instance for every two processes that have information interaction, and loads several middlewares in the middleware instance on each communication channel to manage the interaction process between the two processes, so that each process can share the same container class code to realize the interaction management in the process of inter-process communication, and the interaction management business code between different processes is reused, and will not cause strong intrusion to the original business, which helps to reduce the complexity of the process code.
[0039] The following is a detailed description of each step of the embodiment of the present application.
[0040] Regarding step S1, the information exchange between the two processes may be data exchange or resource sharing. In an application, several processes may be run simultaneously, and any two of the several processes may exchange information.
[0041] The middleware container instance provides management services for the interactive business between two processes of each communication channel. Therefore, a corresponding middleware container instance needs to be created for each two processes that have information interaction.
[0042] In this embodiment, creating a middleware container instance for every two processes that have information interaction includes: running the same middleware container class module to create a corresponding middleware container instance for each communication channel between every two processes that have information interaction.
[0043] Optionally, the middleware container class module is a script written in JavaScript scripting language.
[0044] The IPC communication method is applied in the Electron application. When Electron initializes the rendering process, the rendering process will load a JavaScript script (preload.js) and create an instance of the middleware container in the JavaScript script. Specifically, a corresponding middleware container instance can be created for every two processes that have information interaction, that is, a corresponding middleware container instance is created for each communication channel. Therefore, if Electron has several groups of interacting processes, several middleware container instances are created accordingly, and the middleware in each middleware container instance can be configured according to demand.
[0045] Corresponding middleware container instances are created for multiple communication channels through the same middleware container class module. The code of the same middleware container class module is unique, thereby realizing the reuse of the middleware container class module, that is, realizing the reuse of the middleware container class code, which helps to reduce the complexity of the process code.
[0046] Optional, such as Figure 4 As shown, loading several middlewares in the middleware container instance includes: obtaining the interaction management requirements input by the user, and loading the corresponding middlewares in the middleware container instance according to the interaction management requirements.
[0047] When the middleware container instance is created in the rendering process of Electron, the middleware container instance immediately calls an interface for loading middleware, and loads the middleware into it with the interaction management requirements input by the user as parameters. During the middleware loading process, the interface needs to be called once for each middleware loaded. In each middleware container instance, each middleware corresponds to each interaction management requirement.
[0048] The application developer will determine the corresponding middleware identifier based on the interaction management requirements between the two processes, and input the interaction management requirements or the middleware identifier corresponding to the interaction management requirements into the application development system, so as to load the corresponding middleware in the middleware container instance according to the interaction management requirements.
[0049] The middleware loaded in each middleware container instance may be the same or different. Optionally, the middleware container instance 1 on the communication channel between process 1 and process 2 may include middleware 1, middleware 2, and middleware 3, and the middleware container instance 2 on the communication channel between process 3 and process 4 may only include middleware 1, middleware 2, or other preset middleware. The number of middleware loaded in each middleware container instance may be the same or different.
[0050] Optionally, in the initiation phase of process communication, process 1 initiates the communication, passes through the 1st middleware, the 2nd middleware, ..., the Nth middleware in sequence, and finally reaches process 2; in the reply phase of inter-process communication, process 2 replies to the message of process 1, which flows through the Nth middleware, the N-1th middleware, ..., the 1st middleware in the previous step in sequence, and finally reaches process 1.
[0051] During the initiation phase of inter-process communication, each middleware can obtain the parameters passed by the previous middleware, modify them and pass them to the next middleware, or interrupt and not pass them to the next one, and directly return the results to the previous middleware.
[0052] In the reply phase of inter-process communication, each middleware can obtain the return value from the next middleware and modify it before passing it to the previous middleware.
[0053] In an optional embodiment, if Figure 5 As shown, the interaction management requirement is log printing and / or transmission timeout management; the middleware loaded in each middleware container instance includes: log printing middleware, and / or transmission timeout processing middleware.
[0054] Furthermore, the interactive management requirements may also include other management requirements. The corresponding business management functions can be realized by adding corresponding middleware, which has strong scalability.
[0055] The addition and reduction of middleware in this embodiment is relatively flexible and will not intrude the original process code. When an interactive management service needs to be added, there is no need to modify the original process code. Only the interactive management requirements need to be input and the newly added middleware is loaded in the middleware container instance. The implementation method is simple and flexible.
[0056] Regarding step S2, on each communication channel, the interaction process between the sending process and the receiving process can be: the sending process sends a first interaction message to the receiving process through the various middlewares of the middleware container, and the receiving process replies to the sending process with a second interaction message through the various middlewares of the middleware container, and the second interaction message is an interaction message used to reply to the first interaction message sent by the sending process.
[0057] The first interaction message is an interaction parameter, and the second interaction message is a data value used to reply to the interaction parameter sent by the sending process, such as a return value.
[0058] In this embodiment, if there is data interaction between two processes that interact with each other, each middleware in the middleware container instance receives the interaction data transmitted by the previous middleware, and transmits the interaction data to the next middleware until the interaction data is transmitted to the receiving process. Alternatively, each middleware in the middleware container instance receives the interaction data transmitted by the previous middleware, stops transmitting the interaction data to the next middleware, and transmits the second interaction message back to the sending process through several middlewares at the front end. Furthermore, during the transmission of interaction data between the two processes, each middleware can modify the received interaction data.
[0059] Regarding step S3, managing the interaction process between the two processes may include: log management or service timeout management of the interaction process, or other preset service management. The preset process may be set by the inventor according to demand, and the preset process may be a sending process, a receiving process, or other processes, which is not limited in this embodiment.
[0060] The technical solution of the above-mentioned embodiment of the present application is to create a middleware container instance for every two processes that have information interaction, and load several middlewares in the middleware instances on each communication channel to manage the interaction process between the two processes, so that each process can share the same container class code to realize the interaction management in the process of inter-process communication, and the interaction management business code between different processes is reused, and will not cause strong intrusion to the original business, which helps to reduce the complexity of the process code. Furthermore, the new business does not need to modify the original code, only the corresponding middleware needs to be added, which is non-invasive to the original code. Each middleware can obtain the data flowing in from the previous middleware, can modify the data passed to the next middleware, and has the ability to interrupt the process, and has strong scalability.
[0061] In a second aspect of the embodiments of the present application, an IPC communication device between multiple processes is disclosed. The function limiting device can be used to execute the IPC communication method between multiple processes in the corresponding embodiment of the present application, and has corresponding functions and beneficial effects. For details not disclosed in the embodiment of the IPC communication device between multiple processes of the present application, please refer to the content of the IPC communication method between multiple processes in the above embodiment of the present application.
[0062] See also Figure 6 , Figure 6 This is a structural block diagram of an IPC communication device between multiple processes shown in Example 2 of the present application.
[0063] The IPC communication device between multiple processes includes:
[0064] The instance creation module 101 is used to create a middleware container instance for each two processes that have information interaction, load several middlewares in the middleware container instance, and each two processes that have information interaction perform information interaction through each middleware in the middleware container instance;
[0065] The interaction module 102 is used for, at both ends of each communication channel, the sending process sends a first interaction message to the receiving process through each middleware of the middleware container, and the receiving process replies to the sending process with a second interaction message through each middleware of the middleware container, where the second interaction message is an interaction message used to reply to the sending process;
[0066] The interaction management module 103 is used to manage the interaction process between two processes through various middlewares on each communication channel, and form corresponding data values and return them to the corresponding processes.
[0067] An IPC communication device between multiple processes creates a middleware container instance for every two processes that have information interaction, and loads several middlewares in the middleware instance on each communication channel to manage the interaction process between the two processes, so that each process can share the same container class code to implement interaction management during inter-process communication. The interaction management business codes between different processes are reused, and will not cause strong intrusion on the original business, which helps to reduce the complexity of the process code.
[0068] It is worth noting that the IPC communication device between multiple processes provided in the above embodiment only uses the division of the above functional modules or functional units as an example when executing the above IPC communication method between multiple processes. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the IPC communication device between multiple processes and the IPC communication method between multiple processes provided in the above embodiment belong to the same concept, and the embodiment process is detailed in the embodiment, which will not be repeated here.
[0069] According to a third aspect of an embodiment of the present application, a computer device is provided.
[0070] like Figure 7 As shown, the computer device includes at least one processor 110 and at least one memory 120; the memory 120 is electrically connected to the processor 110 via a communication bus 130; wherein the memory 120 stores a computer program, and the computer program is suitable for being loaded by the processor 120 and executing the IPC communication method between multiple processes disclosed in the above embodiment.
[0071] The processor 110 may include one or more processing cores. The processor uses various interfaces and lines to connect various parts of the entire smart device, and executes various functions of the smart device and processes data by running or executing instructions, programs, code sets or instruction sets stored in the processor, and calling data stored in the memory.
[0072] Among them, the memory 120 may include a random access memory (RAM) or a read-only memory (Read-Only Memory). Optionally, the memory includes a non-transitory computer-readable storage medium. The memory can be used to store instructions, programs, codes, code sets or instruction sets. The memory may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above various method embodiments, etc. The memory as a computer storage medium may include an operating system, a network communication module, a user interface module, and an operating application for a smart device.
[0073] The processor 110 may be used to call an operating application of the smart device stored in the memory, and execute relevant operations in the IPC communication method between multiple processes in the above embodiment.
[0074] The above-mentioned television can be used to execute the contents of the IPC communication method between multiple processes corresponding to the embodiment of the present application, and has corresponding functions and beneficial effects.
[0075] The computer device of this embodiment creates a middleware container instance for every two processes that have information interaction, and loads a number of middleware in the middleware instance on each communication channel to manage the interaction process between the two processes, so that each process can share the same container class code to implement interaction management during inter-process communication. The interaction management business code between different processes is reused, and will not cause strong intrusion on the original business, which helps to reduce the complexity of the process code.
[0076] According to the fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored. The computer program is suitable for being loaded by a processor and executing relevant operations of the IPC communication method between multiple processes as described in the above embodiments, and has corresponding functions and beneficial effects.
[0077] Among them, computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0078] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0079] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. An IPC communication method between multiple processes, characterized in that: The IPC communication method is applied to a multi-process application. The multi-process application starts multiple processes during operation. Two processes that have information interaction implement IPC communication through a communication channel. The IPC communication method includes the following steps: A middleware container instance is created for each two processes that have information interaction, and a plurality of middlewares are loaded into the middleware container instance. Each two processes that have information interaction perform information interaction through each middleware in the middleware container instance. On each communication channel, the sending process sends a first interaction message to the receiving process through each of the middlewares of the middleware container, and the receiving process replies to the sending process with a second interaction message through each of the middlewares of the middleware container, where the second interaction message is an interaction message used to reply to the first interaction message sent by the sending process; The interaction between the two processes is managed through each of the middlewares, and corresponding data values are formed and returned to the preset process.
2. The IPC communication method between multiple processes according to claim 1, characterized in that: The middleware container instance is an instance created when the same middleware container class is running; Creating a middleware container instance for every two processes that have information interaction includes: running the same middleware container class module to create a corresponding middleware container instance for each communication channel between every two processes that have information interaction.
3. The IPC communication method between multiple processes according to claim 1, characterized in that: Load several middlewares in the middleware container instance, including: The interaction management requirement input by the user is obtained, and the corresponding middleware is loaded in the middleware container instance according to the interaction management requirement.
4. The IPC communication method between multiple processes according to claim 3, characterized in that: The interaction management requirement is log printing and / or transmission timeout management; The middleware loaded in each of the middleware container instances includes: log printing middleware, and / or transmission timeout processing middleware.
5. The IPC communication method between multiple processes according to claim 1, characterized in that: If there is data interaction between two processes that interact with information; Each middleware in the middleware container instance receives the interaction data transmitted by the previous middleware, and transmits the interaction data to the next middleware until the interaction data is transmitted to the receiving process, or, Each middleware in the middleware container instance receives the interaction data transmitted by the previous middleware, stops transmitting the interaction data to the next middleware, and returns the second interaction message to the sending process through the front-end middlewares.
6. The IPC communication method between multiple processes according to claim 5, characterized in that: During the transmission of interactive data between two processes, each middleware can modify the received interactive data.
7. The IPC communication method between multiple processes according to any one of claims 1 to 6, characterized in that: The first interaction message is an interaction parameter, and the second interaction message is a data value used to reply to the interaction parameter sent by the sending process.
8. An IPC communication device between multiple processes, characterized in that: include: An instance creation module, used to create a middleware container instance for each two processes that have information interaction, load several middlewares in the middleware container instance, and each two processes that have information interaction perform information interaction through each middleware in the middleware container instance; An interaction module, configured to enable, at both ends of each communication channel, a sending process to send a first interaction message to a receiving process through each of the middlewares of the middleware container, and the receiving process to reply a second interaction message to the sending process through each of the middlewares of the middleware container, wherein the second interaction message is an interaction message used to reply to the sending process; The interaction management module is used to manage the interaction process between two processes through each of the middlewares on each communication channel, and form corresponding data values and return them to the corresponding processes.
9. A computer device comprising at least one processor and at least one memory; the memory is electrically connected to the processor; wherein: The memory stores a computer program, wherein the computer program is suitable for being loaded by the processor and executing the IPC communication method between multiple processes as described in any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: The computer program is suitable for being loaded by the processor and executing the IPC communication method between multiple processes as claimed in any one of claims 1 to 7.
Citation Information
Cited By
Application program processing method and electronic equipment
CN119597498A
