Inter-process communication method and communication system
By receiving and storing inter-process communication request information in the group management module, the problem of poor inter-process communication performance in the prior art is solved, and more stable and accurate inter-process communication is achieved, and communication performance is improved.
Patent Information
- Application Number
- CN202411697230.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-25
- Publication Date
- 2025-04-18
AI Technical Summary
When the prior art uses shared memory to communicate between processes, there are problems such as high memory and CPU consumption and poor communication performance. Especially when multiple processes communicate, synchronization or mutual exclusion may occur, resulting in inconsistent data or other unpredictable exceptions.
Communication between processes is completed by receiving communication request information between processes in the group management module and storing it in the buffer of the target process, so that it reads the request information from the buffer. This method divides multiple processes of the system into multiple communication groups according to communication relationships, and manages the communication relationship between any two processes in any communication group through the group management module, which is equivalent to creating an independent communication link for two processes in the same communication group.
It simplifies the communication method between processes, avoids the mutual exclusion mechanism brought about by synchronous communication of multiple processes, makes communication between processes more stable and accurate, and improves the communication performance between processes.
Smart Images

Figure CN119847782A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to an inter-process communication method and a communication system. Background Art
[0002] With the development of communication technology, shared memory, as a common inter-process communication method, has the highest communication performance in UNIX-like operating systems and is becoming more and more widely used.
[0003] In the related art, when using shared memory for process communication, it is necessary to rely on the shared memory communication library to copy the shared memory and local memory when sending and receiving, which greatly increases the consumption of memory and central processing unit (CPU), and there is a problem of poor inter-process communication performance. Summary of the invention
[0004] Based on this, it is necessary to provide an inter-process communication method and a communication system to address the above technical problems and improve the inter-process communication performance.
[0005] In a first aspect, the present application provides an inter-process communication method, which is applied to a group management module, and the group management module is used to manage the communication between processes in multiple communication groups; the method includes:
[0006] receiving a request message sent by a first process to communicate with a second process; the first process and the second process are any two processes in a same communication group that have a communication relationship;
[0007] The request information is stored in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process.
[0008] In the technical solution provided by the embodiment of the present application, the group management module receives the request information sent by the first process to communicate with the second process, and stores the request information in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process. Among them, the first process and the second process are any two processes with a communication relationship in the same communication group. In this method, multiple processes of the system are divided into multiple communication groups according to the communication relationship, and the communication relationship between any two processes in any communication group is managed by the group management module, which is equivalent to creating an independent communication link for the two processes in the same communication group, simplifying the communication method between processes, avoiding the mutual exclusion mechanism caused by the synchronous communication of multiple processes, making the communication between processes more stable and accurate, and improving the communication performance between processes.
[0009] In one embodiment, receiving request information sent by a first process to communicate with a second process includes:
[0010] Receiving request information sent by a first communication thread corresponding to the first process;
[0011] Accordingly, the request information is stored in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process, including:
[0012] The request information is stored in the buffer of the second process, so that the second communication thread corresponding to the second process reads the request information from the buffer to complete the communication with the first process.
[0013] In the technical solution provided in the embodiment of the present application, the group management module receives the request information sent by the first communication thread corresponding to the first process, and then stores the request information in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process, thereby building a complete and reliable communication link between the first process and the second process.
[0014] In one embodiment, the buffer includes a connection buffer queue, and storing the request information in the buffer of the second process includes:
[0015] The request information is stored in the connection buffer queue of the second process.
[0016] In the technical solution provided in the embodiment of the present application, according to the type of information stored in the buffer, a connection buffer queue is further determined in the buffer of the process, which is used to specifically store request information, so as to improve the speed at which the process reads and responds to the request information, thereby speeding up the communication efficiency between the first process and the second process.
[0017] In one embodiment, the method further comprises:
[0018] Receive a target communication group entry and exit request sent by a target process; the target process is any process in any communication group;
[0019] Verify the legitimacy of the target process and target communication group;
[0020] When the legitimacy verification is passed, the status of the target process and each process in the target communication group is updated.
[0021] In the technical solution provided by the embodiment of the present application, when receiving a target communication group entry and exit request sent by a target process, the legitimacy of the target process and the target communication group is verified to ensure the reliability of the request sent by the target process, and when the legitimacy verification passes, the status of the target process and each process in the target communication group is updated in a timely manner taking into account the impact of the target process on the process communication in the entire target communication group, so as to avoid waste of resources caused by invalid communication requests initiated by processes in the target communication group.
[0022] In one embodiment, the inbound and outbound request is a request to join a group; the buffer includes an event buffer queue; and the state of the target process and each process in the target communication group is updated, including:
[0023] According to the current status of each process in the target communication group, the status of the target process is updated;
[0024] The group entry notification of the target process is stored in the event buffer queue of each process in the target communication group, so as to instruct the communication thread corresponding to each process to read the group entry notification from the event buffer queue to update the status of its own process.
[0025] In the technical solution provided in the embodiment of the present application, the status of the target process is updated according to the current status of each process in the target communication group, and the target process's group entry notification is stored in the event buffer queue of each process in the target communication group, and the target process's group entry message is broadcast to each process in the target communication group, thereby driving the status update of the target communication group and building a more efficient process communication method in the target communication group.
[0026] In one embodiment, updating the state of the target process according to the current state of each process in the target communication group includes:
[0027] If there is a process in the data clearing state in the target communication group, the target process is updated from the current state to the waiting state;
[0028] If there is no process in the data clearing state in the target communication group, the target process is updated from the current state to the start state.
[0029] In the technical solution provided in the embodiment of the present application, the status of the target process is differentially updated based on whether there is a process in the data clearing state in the target communication group. In the scenario where there is a process in the data clearing state in the target communication group, the status of the target process is set to a waiting-to-start state to prevent the target process from initiating invalid communication requests. In the scenario where there is no process in the data clearing state in the target communication group, the status of the target process is set to a starting state to speed up the communication speed between the target process and the processes in the target communication group.
[0030] In one embodiment, the entry and exit request is a request to leave the group, and the buffer includes an event buffer queue; updating the status of the target process and each process in the target communication group includes:
[0031] Get the current status of the target process;
[0032] When the current state is in the preset state list, the target process is updated from the current state to the stop state, and the state of each process in the target communication group is updated to the data clearing state.
[0033] In the technical solution provided by the embodiment of the present application, when the current state of the target process is in the preset state list, the target process is updated from the current state to the stopped state, and the state of each process in the target communication group is updated to the data clearing state, and the file information related to the exiting process is cleaned up in time to save system communication resources.
[0034] In one embodiment, the method further comprises:
[0035] Receive the data clearing progress sent by the communication thread corresponding to each process in the target communication group;
[0036] When each process has completed the data clearing progress, the status of each process in the target communication group is updated to the start status.
[0037] In the technical solution provided in the embodiment of the present application, the data clearing progress sent by the communication thread corresponding to each process in the target communication group is received to facilitate unified updating of the processes of the entire target communication group. When each process has completed the data clearing progress, the status of each process in the target communication group is updated to the startup status to restore the communication between the processes in the target communication group.
[0038] In one embodiment, the method further comprises:
[0039] When it is detected that a process has abnormally left the group, the file exit function is called to close the file that the process has started, and the process is started again until the process resumes joining the group.
[0040] In the technical solution provided by the embodiment of the present application, when it is detected that a process has abnormally exited the group, the file exit function is called to close the file that has been started by the process, and the process is started until the process resumes joining the group. This is equivalent to automatically re-starting the process that has abnormally exited the group in an abnormal state, thereby ensuring the high availability of the process with an abnormal state.
[0041] In a second aspect, the present application further provides a communication system, the communication system comprising a group management module and a plurality of communication groups, each communication group comprising a plurality of processes, and at least one set of process pairs having a communication relationship exists in the same communication group;
[0042] A group management module is used to implement the steps of the method in any one of the embodiments of the first aspect.
[0043] In one embodiment, each process includes a communication thread; the group management module communicates with the process through the communication thread of the process.
[0044] In a third aspect, the present application further provides an inter-process communication device, the device comprising:
[0045] An information receiving module, used for receiving a request message sent by a first process to communicate with a second process; the first process and the second process are any two processes in a same communication group that have a communication relationship;
[0046] The information storage module is used to store the request information in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process.
[0047] In a fourth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the method in any one of the embodiments of the first aspect are implemented.
[0048] In a fifth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method in any one of the embodiments of the first aspect above.
[0049] In a sixth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method in any one of the embodiments of the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0051] Figure 1 An application environment diagram of an inter-process communication method in an embodiment;
[0052] Figure 2 A schematic diagram of a flow chart of an inter-process communication method in one embodiment;
[0053] Figure 3 is a schematic diagram of the architecture of a communication group in one embodiment;
[0054] Figure 4 A schematic diagram of process communication of a communication group in one embodiment;
[0055] Figure 5 It is a flowchart of a process status update step in one embodiment;
[0056] Figure 6 A schematic diagram of process state transition of a communication group in one embodiment;
[0057] Figure 7 It is a flowchart of a process status update step in another embodiment;
[0058] Figure 8 It is a flowchart of a process status update step in another embodiment;
[0059] Fig. 9 It is a flowchart of a process status update step in another embodiment;
[0060] Fig.10 It is a flowchart of a process status update step in another embodiment;
[0061] Fig.11 It is a flowchart of a process status update step in another embodiment;
[0062] Fig.12 It is a flowchart of a process status update step in another embodiment;
[0063] Fig.13 A schematic diagram of inter-process communication of a communication system in another embodiment;
[0064] Fig.14 is a structural block diagram of an inter-process communication device in one embodiment;
[0065] Fig.15 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0067] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0068] The technical background of this application is first described below.
[0069] With the development of communication technology, shared memory, as a common inter-process communication method, has the highest communication performance in UNIX-like operating systems and is becoming more and more widely used.
[0070] In the related art, when using shared memory for process communication, the copying of shared memory and local memory is involved when sending and receiving, which greatly increases the consumption of memory and CPU, making the transmission performance of inter-process communication poor. In addition, in the case of multiple process communication, synchronization or mutual exclusion problems may occur, which may cause data inconsistency or other unpredictable exceptions. In order to solve this problem, the introduction of synchronization mechanisms, such as semaphores, mutex locks, etc., will involve certain overhead, reduce communication efficiency, and may also cause deadlock and other problems, and there is a problem of poor inter-process communication performance. In addition, the inter-process communication methods provided in the prior art are usually broad in content, and their practical design and cost are large.
[0071] Based on this, the implementation of this application provides a practical inter-process communication method and communication system for more detailed scenarios to solve the above problems. Of course, the technical solution provided in the embodiments of this application is not limited to solving the above problems, and there are other technical effects, which can be specifically referred to in the following embodiment description.
[0072] Before describing the embodiments of the present application, the application scenarios of the embodiments of the present application are described first.
[0073] The inter-process communication method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the communication group includes multiple groups of processes with communication relationships. On the basis of establishing connection relationships, information can be transmitted between processes through the group management module, and the group management module is used to manage the communication between processes in multiple communication groups.
[0074] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0075] In an exemplary embodiment, Figure 2 As shown, a method for inter-process communication is provided, which is applied to Figure 1 The group management module in the example is used to manage the communication between processes in multiple communication groups; the method includes:
[0076] S201, receiving request information sent by a first process to communicate with a second process; the first process and the second process are any two processes in the same communication group that have a communication relationship.
[0077] The communication group is a set of processes that have a communication relationship, including multiple processes. Figure 3 is a schematic diagram of the structure of a communication group. Figure 3 In the ,a single communication group includes multiple processes, and each process includes a communication memory for storing ,communication information sent by other processes. Figure 3 In the process, after two processes establish a connection relationship, threads between the processes communicate through the communication memory of the processes, for example, the sender stores the communication information in the communication memory of the receiver.
[0078] In a communication scenario, the complete communication process between two processes can be divided into three stages: connection relationship establishment, communication information transmission, and connection relationship disconnection. The group management module in the embodiment of the present application is responsible for creating a connection relationship between two processes in the same communication group. After the connection relationship is created between the two processes, the "thread pair" between the two processes can communicate directly. Furthermore, after the two processes create a connection relationship, the group management module is also responsible for disconnecting the connection relationship between the two processes.
[0079] Next, taking the first process as the information sending end and the second process as the information receiving end as an example, the interaction between the group management module and the first process and the second process during the process of establishing or disconnecting the connection relationship between the first process and the second process is described.
[0080] Optionally, the request information is a connection relationship establishment request, the group management module receives the connection relationship establishment request sent by the first process, determines the second process based on the process identifier carried in the connection relationship establishment request, and establishes a communication relationship between the first process and the second process.
[0081] Optionally, the request information is a connection disconnection request, the group management module receives the connection disconnection request sent by the first process, determines the second process based on the process identifier carried in the connection disconnection request, and disconnects the communication relationship between the first process and the second process.
[0082] S202, storing the request information in a buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process.
[0083] Each process in the communication group has a corresponding buffer, that is, Figure 3 The communication memory shown is used to store the communication information sent by other processes in the communication group. The buffer of each process can be a collection of multiple independent memory areas, which are used to distinguish the communication information sent by different processes. For example, there is a connection relationship between process A, process B and process C in the same communication group. Figure 4 This is a schematic diagram of the process buffers in the communication group. The buffer area of process A includes an idle buffer, a buffer for storing communication messages of process B, and a buffer for storing communication messages of process C; the buffer area of process B includes an idle buffer, a buffer for storing communication messages of process A, and a buffer for storing communication messages of process C; the buffer area of process C includes an idle buffer, a buffer for storing communication messages of process A, and a buffer for storing communication messages of process B.
[0084] In another communication scenario, the buffer of each process can also be an independent memory space used to uniformly store communication information sent by other processes.
[0085] After receiving the request information sent by the first process, the group management module stores the request information sent by the first process into a buffer for determining the second process, so that the second process responds according to the request information and completes the communication with the first process.
[0086] Taking the example that the request information is a connection relationship establishment request, the group management module stores the connection relationship establishment request in the buffer of the second process. The second process sends a connection relationship establishment response to the group management module based on the read connection relationship establishment request. The group management module forwards the connection relationship establishment response to the first process, completes the connection relationship between the first process and the second process, so that the first process and the second process can communicate directly in the future.
[0087] Taking the request information being a connection relationship disconnection request as an example, the group management module stores the connection relationship disconnection request in the buffer of the second process. The second process sends a connection relationship disconnection response to the group management module based on the read connection relationship disconnection request. The group management module forwards the connection relationship disconnection response to the first process, disconnects the connection relationship between the first process and the second process, so as to inform the first process that in the scenario where communication is required again in the future, a connection relationship establishment request needs to be initiated to realize communication between the two processes.
[0088] In addition to setting the buffer of each process as a set of multiple independent memory areas or an independent memory space according to the communication relationship between processes, the buffer of each process can also be divided into a connection buffer queue and an event buffer queue according to the type of information stored in the buffer.
[0089] In an exemplary embodiment, the buffer includes a connection buffer queue, and storing the request information in the buffer of the second process includes:
[0090] The request information is stored in the connection buffer queue of the second process.
[0091] Regardless of whether the request information is a connection establishment request information or a connection disconnection request information, the group management module stores the request information sent by the first process in the connection buffer queue of the second process to instruct the communication thread of the second process to perceive and read the request information from the connection buffer queue in a timely manner.
[0092] In an embodiment of the present application, according to the type of information stored in the buffer, a connection buffer queue is further determined in the buffer of the process for specifically storing request information to increase the speed at which the process reads and responds to the request information, thereby speeding up the communication efficiency between the first process and the second process.
[0093] In an embodiment of the present application, a group management module receives a request message sent by a first process to communicate with a second process, and stores the request message in a buffer of the second process, so that the second process reads the request message from the buffer to complete the communication with the first process. The first process and the second process are any two processes in the same communication group that have a communication relationship. In this method, multiple processes of the system are divided into multiple communication groups according to the communication relationship, and the communication relationship between any two processes in any communication group is managed by the group management module, which is equivalent to creating an independent communication link for two processes in the same communication group, simplifying the communication method between processes, avoiding the mutual exclusion mechanism caused by synchronous communication of multiple processes, making the communication between processes more stable and accurate, and improving the communication performance between processes.
[0094] Each process in the communication group includes a corresponding communication thread as an agent for the process to interact with the group management module. In an exemplary embodiment, receiving a request message sent by a first process to communicate with a second process includes: receiving a request message sent by a first communication thread corresponding to the first process; correspondingly, storing the request message in a buffer of the second process so that the second process reads the request message from the buffer to complete the communication with the first process, including:
[0095] The request information is stored in the buffer of the second process, so that the second communication thread corresponding to the second process reads the request information from the buffer to complete the communication with the first process.
[0096] It should be noted that each process has only one communication thread. In the embodiment of the present application, the communication thread of the first process is determined as the first communication thread, and the communication thread of the second process is determined as the second communication thread to distinguish the communication threads of different processes.
[0097] In addition, in the communication scenario, threads in the same process share memory, based on which the communication thread can directly read information from the buffer of the process to which it belongs. To maximize the use of the buffer of each process, the communication thread clears the information read by the communication thread each time it reads information from the buffer. In addition, when the buffer information is cleared, the communication thread automatically enters a dormant state, and when there is unread information stored in the buffer, the communication thread is automatically awakened to avoid waste of air interface resources caused by the continuous idleness of the communication thread.
[0098] During the communication between the first process and the second process, the group management module receives the request information sent by the first communication thread, and stores the received request information in the buffer of the second process to inform the second communication thread to read the request information from the buffer in time.
[0099] In an embodiment of the present application, the group management module receives the request information sent by the first communication thread corresponding to the first process, and then stores the request information in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process, thereby building a complete and reliable communication link between the first process and the second process.
[0100] The connection relationship between processes in each communication group is changing dynamically. During the dynamic change process, a single process may leave or join a group, thereby affecting the communication status between processes in the communication group corresponding to the process. Based on this, the embodiment of the present application provides a state machine mechanism, which drives the status update of each process based on the event of a single process joining or leaving the group, thereby controlling whether each process can communicate.
[0101] In an exemplary embodiment, Figure 5 As shown, the method also includes:
[0102] S501, receiving a target communication group entry and exit request sent by a target process; the target process is any process in any communication group.
[0103] The target process may be a process that needs to communicate with a process in the target communication group but has not entered the target communication group, or a process that has completed communication with a process in the target communication group and is in the target communication group.
[0104] The entry and exit request includes a group entry request or a group exit request. If the target process is a process that has not entered the target communication group, the entry and exit request is a group entry request; if the target process is a process that has entered the target communication group, the entry and exit request is a group exit request.
[0105] S502, verify the legitimacy of the target process and the target communication group.
[0106] The kernel group management module records the information of each process of multiple communication groups, including the information of the communication group and the description information of the process. The information of the communication group includes but is not limited to the name of the communication group and the number of processes in the communication group. The description information of the process is a string that describes the process, including but not limited to the process status, process communication buffer, process identifier (Process ID, PID), and thread identifier (Thread ID, TID) information.
[0107] Perform a legitimacy verification on the target process identifier and the target communication group name to determine whether the target process and the target communication group comply with the naming rules of the communication system. If the target process identifier and the target communication group name comply with the naming rules of the communication system, then the legitimacy verification is determined to have passed. If the target process identifier and / or the target communication group name do not comply with the naming rules of the communication system, then the legitimacy verification is determined to have failed, an exception indication message is generated, and the execution status update is terminated.
[0108] S503: When the legitimacy verification is passed, the status of the target process and each process in the target communication group is updated.
[0109] If the legitimacy verification passes, in response to the target communication group entry and exit request sent by the target process, based on the current status of each process in the target communication group and the current status of the target process, the update status of the target process and the update status of each process in the target communication group are determined, and the status of each process in the target communication group is updated to the corresponding update status, and the status of the target process is updated to the corresponding update status.
[0110] In an embodiment of the present application, when receiving a target communication group entry and exit request sent by a target process, a legitimacy verification is performed on the target process and the target communication group to ensure the reliability of the request sent by the target process, and when the legitimacy verification passes, the status of the target process and each process in the target communication group is updated in a timely manner taking into account the impact of the target process on the process communication in the entire target communication group, so as to avoid waste of resources caused by invalid communication requests initiated by processes in the target communication group.
[0111] Next, the state machine mechanism provided in the embodiment of the present application is first described, and then the state update steps of the group management module in different scenarios are described.
[0112] See also Figure 6 , Figure 6 A schematic diagram of the state machine mechanism. Figure 6 The states of the process include: initial (INIT) state, waiting to start state (STARTING), starting state (START), clearing state (DIRTY), stopping state (STOP) and death state (DEAD).
[0113] Among them, the INIT state is the state in which the process has not joined the communication group. The STARTING state is when there is a DIRTY process in the communication group. After the process joins the group, it will become the STARTING state. The STARTING state is not a normal working state and does not provide communication capabilities. After all the DIRTY processes in the communication group have completed the memory task cleanup, the process in the STARTING state will enter the START state. When a process in the communication group leaves the group, the process in the SATRT state in the communication group will be converted to the DIRTY state. The process in the DIRTY state needs to perform the memory task cleanup, and it will not be converted to the START state until the cleanup is completed. After the process leaves the group, it is in the STOP state. Regardless of whether the process ends execution normally or abnormally, it will enter the DEAD state. Any other state will enter the DEAD state when the process dies abnormally.
[0114] Next, the status update steps of the group management module are described in the scenario where the target process is a process that has not entered the target communication group.
[0115] In an exemplary embodiment, the entry and exit request is a request to enter a group; Figure 7 As shown, the buffer includes an event buffer queue; the status of the target process and each process in the target communication group is updated, including:
[0116] S701, updating the state of the target process according to the current state of each process in the target communication group.
[0117] In order to prevent the target process from repeatedly initiating requests to join the group, it is possible to determine whether the target process is already in the target communication group before updating the status of the target process. If the target process is already in the target communication group, it means that the target process has repeatedly initiated requests to join the group, and the current request to join the group will not be processed and an exception will be returned; if the target process is not in the target communication group, it means that the target process has initiated a request to join the group for the first time and the current state of the target process is in the initial state, and the state of the target process is updated according to the current state of each process in the target communication group.
[0118] In an optional embodiment, the group management module can store the current status of each process in the target communication group to the buffer of the target process, instruct the communication thread of the target process to read the current status of each process in the buffer, and update the status of the target process based on the current status of each process. The group management module can also directly determine the status to be updated of the target process according to the status of the target process, and store it in the buffer of the target process, instruct the communication thread of the target process to read the status to be updated of the target process in the buffer, and complete the process status update.
[0119] In an exemplary embodiment, updating the state of the target process according to the current state of each process in the target communication group includes:
[0120] If there is a process in the data clearing state in the target communication group, the target process is updated from the current state to the waiting state; if there is no process in the data clearing state in the target communication group, the target process is updated from the current state to the starting state.
[0121] If there is a process in the data clearing state in the target communication group, it means that the process in the target communication group is not yet in a normal communication state. At this time, even if the target process enters the target communication group, it cannot communicate with the process in the target communication group. The target process is updated from the initial state to the waiting state, and waits for the process in the target communication group to recover to the normal communication state, and the state of the target process is updated to the starting state.
[0122] If there is no process in the data clearing state in the target communication group, it means that the processes in the target communication group are in a normal communication state. At this time, the target process enters the target communication group and can directly communicate with the processes in the target communication group, and the target process is updated from the initial state to the startup state.
[0123] In an embodiment of the present application, based on whether there is a process in a data clearing state in the target communication group, the state of the target process is updated differentially. In a scenario where there is a process in a data clearing state in the target communication group, the state of the target process is set to a waiting-to-start state to prevent the target process from initiating invalid communication requests. In a scenario where there is no process in a data clearing state in the target communication group, the state of the target process is set to a starting state to speed up the communication speed between the target process and the processes in the target communication group.
[0124] S702, storing the group entry notification of the target process in the event buffer queue of each process in the target communication group, so as to instruct the communication thread corresponding to each process to read the group entry notification from the event buffer queue to update the status of its own process.
[0125] The target process's group entry notification is stored in the event buffer queue of each process in the target communication group, and the target process's group entry message is broadcast to each process in the target communication group to drive the target communication group's status update. Each process in the target communication group can continue to maintain its current status by reading the group entry notification from the event buffer queue based on the communication thread. For example, when the process is in the startup state, it can establish a connection relationship with the target process and communicate.
[0126] In an embodiment of the present application, the status of the target process is updated according to the current status of each process in the target communication group, and the notification of the target process joining the group is stored in the event buffer queue of each process in the target communication group, and the message of the target process joining the group is broadcast to each process in the target communication group, thereby driving the status update of the target communication group and building a more efficient process communication method in the target communication group.
[0127] See also Figure 8 , Figure 8 In a scenario where a request to join a group is initiated for a target process, an embodiment of a group management module updating a status includes the following steps:
[0128] S801, receiving a group joining request sent by a target process.
[0129] S802: Determine whether the name of the target communication group is legal.
[0130] If it is legal, execute step S803; if it is illegal, execute step S807.
[0131] S803, determining whether the target process identifier is legal.
[0132] If it is legal, execute step S804; if it is illegal, execute step S807.
[0133] S804, locking the target process and the target communication group.
[0134] S805, determining whether the target process has entered the target communication group.
[0135] If entered, execute step S806; if not entered, execute step S808.
[0136] S806, unlock the target process and the target communication group, and execute step S807.
[0137] S807, returns an exception.
[0138] S808, updating the process information of the target communication group.
[0139] S809, determining whether there is a process in a clearing state in the target communication group.
[0140] If yes, execute step S810, if no, execute step S811.
[0141] S810, updating the state of the target process to a waiting-to-start state.
[0142] S811, update the state of the target process to the start state.
[0143] S812, broadcast the target process's group entry notification.
[0144] S813, return to normal.
[0145] In an embodiment of the present application, during the process of the target process entering the group, a series of checks are performed on the target process to ensure the reliability of the target process entering the group event. Then, when the target process passes the check, the status of each process in the target communication group including the target process is driven to update, thereby providing a complete and specific high-availability mechanism based on the communication group.
[0146] Next, the status update steps of the group management module are described in the scenario where the target process is a process that has entered the target communication group.
[0147] In an exemplary embodiment, the entry and exit request is a request to leave the group, such as Fig. 9 As shown, the buffer includes an event buffer queue; the status of the target process and each process in the target communication group is updated, including:
[0148] S901, obtain the current state of the target process.
[0149] The target process is in the target communication group, and the current state of the target process can be a waiting state, a starting state, a clearing state, a state not defined in the embodiment of the present application, etc.
[0150] The group management module can determine the current state of the target process by communicating with the communication thread of the target process in a scheduled or real-time manner.
[0151] S902, when the current state is in the preset state list, the target process is updated from the current state to the stop state, and the state of each process in the target communication group is updated to the data clearing state.
[0152] The preset status list includes the waiting to start status, the starting status and the clearing status. If the current status of the target process is not in any of the preset status lists, it means that the target process meets the conditions for leaving the group, and the target process is updated from the current state to the stopped state. At the same time, considering that the communication between the target process and other processes in the target communication group will generate communication cache information, the status of each process in the target communication group is updated to the data clearing state to instruct the remaining processes in the target communication group to clean up the cache information.
[0153] In an embodiment of the present application, when the current state of the target process is in the preset state list, the target process is updated from the current state to the stopped state, and the state of each process in the target communication group is updated to the data clearing state, and the file information related to the exiting process is cleaned up in time to save system communication resources.
[0154] See also Fig.10 , Fig.10 In a scenario where a request to leave a group is initiated for a target process, an embodiment of a group management module updating a status includes the following steps:
[0155] S1001, receiving a withdrawal request sent by a target process.
[0156] S1002, determining whether the name of the target communication group is legal.
[0157] If it is legal, execute step S1003; if it is illegal, execute step S1008.
[0158] S1003, determining whether the target process identifier is legal.
[0159] If it is legal, execute step S1004; if it is illegal, execute step S1008.
[0160] S1004, determining whether the target communication group matches the target process.
[0161] If there is a match, execute step S1005; if there is no match, execute step S1008.
[0162] S1005, lock the target process and the target communication group.
[0163] S1006, determining whether the state of the target process is in a preset state list.
[0164] If not, execute step S1007; if so, execute step S1008.
[0165] S1007, unlock the target process and target communication group, and return an exception.
[0166] S1008, returns an exception.
[0167] S1009, update the state of the target process to a stopped state.
[0168] S1010, updating the process in the startup state to a process in the clearing state.
[0169] S1011, waking up the communication thread of the process in the clearing state.
[0170] S1012, initiate a request to leave the group, and broadcast a notification of joining or leaving the group of the target process.
[0171] S1013, return to normal.
[0172] In an embodiment of the present application, during the process of the target process leaving the group, a series of checks are performed on the target process to ensure the reliability of the target process leaving the group event. Then, when the target process passes the check, the status of each process in the target communication group including the target process is driven to update, providing a complete and specific high-availability mechanism based on the communication group.
[0173] In an exemplary embodiment, Fig.11 As shown, the method also includes:
[0174] S1101, receiving data clearing progress sent by the communication thread corresponding to each process in the target communication group.
[0175] For processes in the clearing state, as the clearing process continues, the information to be cleared becomes less and less until it is cleared, and there is no need to maintain the clearing state. Based on this, considering the dynamic changes in the clearing progress, the group management module receives the data clearing progress sent by the communication thread corresponding to each process in the target communication group at regular intervals or in real time.
[0176] If the data clearing progress of at least one process has not been completed, continue to wait for the process to be cleared until the data clearing progress of each process is completed.
[0177] S1102, when each process has completed the data clearing progress, the status of each process in the target communication group is updated to the startup status.
[0178] When each process completes the data clearing progress, the relevant interface can be called to notify the target communication group to indicate that the status of each process is changed from clearing to starting.
[0179] In an embodiment of the present application, the data clearing progress sent by the communication thread corresponding to each process in the target communication group is received to facilitate a unified update of the processes of the entire target communication group. When each process has completed the data clearing progress, the status of each process in the target communication group is updated to a started status to restore communication between the processes in the target communication group.
[0180] See also Fig.12 , Fig.12 In a scenario where a request to leave a group is initiated for a target process, an embodiment of a group management module updating a status includes the following steps:
[0181] S1201, receiving a withdrawal request sent by a target process.
[0182] S1202, determining whether the name of the target communication group is legal.
[0183] If it is legal, execute step S1203; if it is illegal, execute step S1210.
[0184] S1203, determine whether the identifier of the target process is legal.
[0185] If it is legal, execute step S1204; if it is illegal, execute step S1210.
[0186] S1204, determining whether the target communication group matches the target process.
[0187] If there is no match, execute step S1205; if there is a match, execute step S1210.
[0188] S1205, lock the target process and the target communication group.
[0189] S1206, determining whether the target process is in a clearing state.
[0190] If yes, execute step S1207; if no, execute step S1209.
[0191] S1207, unlock the target process and the target communication group, and execute step S1208.
[0192] S1208, returns an exception.
[0193] S1209, determining whether there is a process in a clearing state in the target communication group.
[0194] If it does not exist, execute step S1210; if it does exist, execute step S1211.
[0195] S1210, update the status of each process in the target communication group owner to the startup status.
[0196] S1211, unlock the target process and target communication group.
[0197] S1212, return to normal.
[0198] In an embodiment of the present application, during the process of the target process leaving the group, a series of checks are performed on the target process to ensure the reliability of the target process leaving the group event. Then, when the target process passes the check and the target communication group does not include processes in the clearing state, the state of each process in the target communication group is driven to update to the startup state, and the communication between the processes in the target communication group is restored.
[0199] The above embodiment describes the implementation method of state update in the scenario where the target process normally initiates a request to join or leave a group. Next, the management method of the group management module in the scenario where the process abnormally leaves a group is described.
[0200] In an exemplary embodiment, the method further comprises:
[0201] When it is detected that a process has abnormally left the group, the file exit function is called to close the file that the process has started, and the process is started again until the process resumes joining the group.
[0202] It should be noted that after the process is started, a specific file ( / proc / khelper) will be opened. The operation of the opened file (file_operations.release()) needs to be registered as a unique function, which is used to call the release function to notify related modules when the process exits.
[0203] When the kernel group management module detects an abnormal exit, it calls the file exit (doexit) function to close the files opened by the process in sequence. At the same time, in the process of closing the " / proc / khelper" file, its associated file operations.release() function is executed, specifically executing the relevant operations of the process exiting the communication group.
[0204] Taking the case where the abnormally exited process is not a user-mode process and the group management module is a kernel management module as an example, when sensing that the user-mode process has abnormally exited, the group management module can start the user process in kernel mode through the call_usermodehelper function provided by the operating system graph content, such as the Linux system kernel.
[0205] In an embodiment of the present application, when it is detected that a process has abnormally exited the group, the file exit function is called to close the file that the process has started, and the process is started until the process resumes joining the group. This is equivalent to automatically re-starting the process that has abnormally exited the group in an abnormal state, thereby ensuring the high availability of the process with an abnormal state.
[0206] In an exemplary embodiment, an inter-process communication method is provided, which is applied to a group management module, where the group management module is used to manage communication between processes in a plurality of communication groups; the method comprises:
[0207] (1) Receive the target communication group joining request sent by the target process.
[0208] (2) Verify the legitimacy of the target process and target communication group.
[0209] (3) If the legitimacy verification passes, the status of the target process is updated according to the current status of each process in the target communication group.
[0210] If there is a process in the data clearing state in the target communication group, the target process is updated from the current state to the waiting state; if there is no process in the data clearing state in the target communication group, the target process is updated from the current state to the starting state.
[0211] (4) Receive request information sent by the first communication thread corresponding to the first process.
[0212] (5) The request information is stored in the connection buffer queue of the second process, so that the second communication thread corresponding to the second process reads the request information from the buffer to complete the communication with the first process.
[0213] (6) Broadcast the target process’s entry notification in the target communication group.
[0214] (7) Receive the target communication group withdrawal request sent by the target process and obtain the current status of the target process.
[0215] (8) When the current state is in the preset state list, the target process is updated from the current state to the stop state, and the state of each process in the target communication group is updated to the data clearing state.
[0216] (9) Receive the data clearing progress sent by the communication threads corresponding to each process in the target communication group.
[0217] (10) When all processes have completed the data clearing progress, the status of each process in the target communication group is updated to the startup status.
[0218] (11) When it is detected that a process has abnormally left the group, the file exit function is called to close the file that the process has started, and the process is started again until the process resumes joining the group.
[0219] In an embodiment of the present application, multiple processes of the system are divided into multiple communication groups according to the communication relationship, and the communication relationship between any two processes in any communication group is managed by the group management module, which is equivalent to creating an independent communication link for the two processes in the same communication group, thereby simplifying the communication method between processes, avoiding the mutual exclusion mechanism caused by synchronous communication of multiple processes, making the communication between processes more stable and accurate, and improving the communication performance between processes.
[0220] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0221] Based on the same inventive concept, an embodiment of the present application also provides a communication system for implementing the above-mentioned aspects, wherein the communication system includes a group management module and multiple communication groups, each communication group includes multiple processes, and there is at least one group of process pairs with a communication relationship in the same communication group; the group management module is used to implement the steps of the method in any of the above-mentioned embodiments.
[0222] In an exemplary embodiment, each process in the communication system includes a communication thread; the group management module communicates with the process through the communication thread of the process. Fig.13 , Fig.13 It is a schematic diagram of a process communicating with a group management module through a communication thread. Fig.13In the process A, a request to join a group, a request to leave a group, a request to create a connection relationship, and a request to disconnect a connection relationship can be sent to the group management module through the communication thread. Based on the received information, the group management module returns a response to join a group, a response to leave a group, a response to create a connection relationship, and a response to disconnect a connection relationship to process A through the communication thread of process A. The information related to the communication group is stored in the kernel, and the relevant information needs to be updated when the process joins or leaves the group. In addition, the kernel records the information of each process in multiple communication groups, and any process can obtain the information by sending a query request to the kernel through the interface. The kernel state has one and only one communication thread, which serves the kernel state of the communication group.
[0223] Based on the same inventive concept, the embodiment of the present application also provides an inter-process communication device for implementing the inter-process communication method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more inter-process communication device embodiments provided below can refer to the above limitations on the inter-process communication method, which will not be repeated here.
[0224] In an exemplary embodiment, Fig.14 As shown, an inter-process communication device is provided, including: an information receiving module 1401 and an information storage module 1402, wherein:
[0225] The information receiving module 1401 is used to receive a request message sent by a first process to communicate with a second process; the first process and the second process are any two processes in the same communication group that have a communication relationship;
[0226] The information storage module 1402 is used to store the request information in the buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process.
[0227] In an exemplary embodiment, the information receiving module 1401 is used to receive request information sent by a first communication thread corresponding to a first process;
[0228] The information storage module 1402 is used to store the request information in the buffer of the second process, so that the second communication thread corresponding to the second process reads the request information from the buffer to complete the communication with the first process.
[0229] In an exemplary embodiment, the buffer includes a connection buffer queue, and the information storage module 1402 is used to store the request information in the connection buffer queue of the second process.
[0230] In an exemplary embodiment, an inter-process communication device includes: a request receiving module, an information verification module and a status updating module, wherein:
[0231] A request receiving module, used for receiving a target communication group entry and exit request sent by a target process; the target process is any process in any communication group;
[0232] Information verification module, used to verify the legitimacy of the target process and target communication group;
[0233] The status update module is used to update the status of the target process and each process in the target communication group when the legitimacy verification is passed.
[0234] In an exemplary embodiment, the in / out request is a group entry request; the buffer includes an event buffer queue; the state update module includes a first update unit and a second update unit, wherein:
[0235] A first updating unit, configured to update the state of a target process according to the current state of each process in the target communication group;
[0236] The second updating unit is used to store the group entry notification of the target process in the event buffer queue of each process in the target communication group, so as to instruct the communication thread corresponding to each process to read the group entry notification from the event buffer queue to update the state of its own process.
[0237] In an exemplary embodiment, the first update unit is used to update the target process from the current state to the to-be-started state when there is a process in the data clearing state in the target communication group; and to update the target process from the current state to the started state when there is no process in the data clearing state in the target communication group.
[0238] In an exemplary embodiment, the in / out request is a degroup request, the buffer includes an event buffer queue; the state update module includes a state acquisition unit and a state driving unit, wherein:
[0239] A state acquisition unit, used to obtain the current state of the target process;
[0240] The state driving unit is used to update the target process from the current state to the stop state when the current state is in the preset state list, and to update the state of each process in the target communication group to the data clearing state.
[0241] In an exemplary embodiment, an inter-process communication device includes: a progress receiving module and a status restarting module, wherein:
[0242] A progress receiving module is used to receive the data clearing progress sent by the communication thread corresponding to each process in the target communication group;
[0243] The status restart module is used to update the status of each process in the target communication group to the startup state when each process has completed the data clearing progress.
[0244] In an exemplary embodiment, an inter-process communication device includes: a process starting module, which is used to call a file exit function to close the file started by the process when it is detected that the process abnormally exits the group, and start the process until the process resumes joining the group.
[0245] Each module in the above-mentioned inter-process communication device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.
[0246] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Fig.15 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store inter-process communication data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, an inter-process communication method is implemented.
[0247] Those skilled in the art will understand that Fig.15 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0248] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0249] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0250] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0251] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0252] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0253] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0254] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An inter-process communication method, characterized in that: Applied to a group management module, the group management module is used to manage communications between processes in multiple communication groups; the method comprises: receiving a request message sent by a first process to communicate with a second process; the first process and the second process are any two processes in a same communication group that have a communication relationship; The request information is stored in a buffer of the second process, so that the second process reads the request information from the buffer to complete the communication with the first process.
2. The method according to claim 1, characterized in that The receiving request information sent by the first process to communicate with the second process includes: Receiving the request information sent by the first communication thread corresponding to the first process; Correspondingly, storing the request information in the buffer of the second process so that the second process reads the request information from the buffer to complete the communication with the first process includes: The request information is stored in a buffer of the second process, so that a second communication thread corresponding to the second process reads the request information from the buffer to complete communication with the first process.
3. The method according to claim 1, characterized in that The buffer includes a connection buffer queue, and storing the request information in the buffer of the second process includes: The request information is stored in the connection buffer queue of the second process.
4. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: Receiving a target communication group entry and exit request sent by a target process; the target process is any process in any communication group; Performing legitimacy verification on the target process and the target communication group; When the legality verification is passed, the status of the target process and each process in the target communication group is updated.
5. The method according to claim 4, characterized in that The entry and exit request is a request to enter a group; the buffer includes an event buffer queue; and the updating of the status of the target process and each process in the target communication group includes: According to the current status of each process in the target communication group, updating the status of the target process; The group entry notification of the target process is stored in the event buffer queue of each process in the target communication group, so as to instruct the communication thread corresponding to each process to read the group entry notification from the event buffer queue to update the state of its own process.
6. The method according to claim 5, characterized in that The updating of the state of the target process according to the current state of each process in the target communication group includes: If the target communication group has a process in a data clearing state, updating the target process from a current state to a waiting-to-start state; If the target communication group does not have a process in a data clearing state, the target process is updated from a current state to a start state.
7. The method according to claim 4, characterized in that The entry and exit request is a withdrawal request, the buffer includes an event buffer queue; and the updating of the status of the target process and each process in the target communication group includes: Obtaining the current state of the target process; In the case that the current state is in the preset state list, the target process is updated from the current state to the stop state, and the state of each process in the target communication group is updated to the data clearing state.
8. The method according to claim 7, characterized in that The method further comprises: Receive data clearing progress sent by the communication thread corresponding to each process in the target communication group; When all the processes have completed the data clearing progress, the status of each process in the target communication group is updated to a startup status.
9. The method according to any one of claims 1 to 3, characterized in that: The method further comprises: When it is detected that a process has abnormally left the group, the file exit function is called to close the file started by the process, and the process is started again until the process resumes joining the group.
10. A communication system, characterized in that: The communication system includes a group management module and a plurality of communication groups, each communication group includes a plurality of processes, and at least one process pair having a communication relationship exists in the same communication group; The group management module is used to implement the steps of any one of the methods of claims 1 to 9.
11. The system according to claim 10, characterized in that Each process includes a communication thread; the group management module communicates with the process through the communication thread of the process.