Inter-process data transmission method, device, electronic device and storage medium
By using data flow identification and busy waiting polling detection of bitmap fields in inter-process communication, efficient inter-process data transmission is achieved, solving the problems of low efficiency and high latency in the prior art.
Patent Information
- Application Number
- CN202410010223.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-03
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-01-03
AI Technical Summary
In the prior art, there are problems of low efficiency and high latency between processes.
By creating a local inter-process communication connection for the first program process and the second program process, a data flow identifier is obtained, and after writing the target data in the shared memory, a read-write status value is written to the bitmap field of the shared memory, and the second program process is triggered. The data acquisition operation of the second program process can realize data transmission, avoid system calls, and save resource overhead.
Improve data transmission efficiency, reduce waiting delay, and realize efficient inter-process data transmission.
Smart Images

Figure CN117762658B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present disclosure relate to the field of computer technology, and in particular, to a method, device, electronic device, and storage medium for inter-process data transmission. Background Art
[0002] Currently, for different local processes, efficient data transmission between processes can be achieved through local inter-process communication and shared memory technology.
[0003] However, the inter-process data transmission scheme in the prior art has the problems of low data transmission efficiency and high latency. Summary of the invention
[0004] The embodiments of the present disclosure provide a method, device, electronic device and storage medium for inter-process data transmission to overcome the problems of low data transmission efficiency and high delay in inter-process communication.
[0005] In a first aspect, an embodiment of the present disclosure provides an inter-process data transmission method, including:
[0006] After establishing a local inter-process communication connection between the first program process and the second program process, obtaining a data flow identifier through the first program process;
[0007] Writing target data to a data buffer area of a shared memory through the first program process, and after the target data is written, writing a first read-write status value to a target position of a first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier;
[0008] The first bitmap field of the shared memory is busy-waited polled by the second program process. If the first read-write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data cache.
[0009] In a second aspect, an embodiment of the present disclosure provides an inter-process data transmission device, including:
[0010] an acquisition module, configured to obtain a data flow identifier through the first program process after establishing a local inter-process communication connection between the first program process and the second program process;
[0011] A writing module, used for writing target data to a data buffer area of a shared memory through the first program process, and after the target data is written, writing a first read-write status value to a target position of a first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier;
[0012] a reading module, configured to perform a busy wait polling detection on the first bitmap field of the shared memory through the second program process, and if the first read-write status value is detected at the target position of the first bitmap field, obtain the target data output by the first program process from the data buffer area;
[0013] In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a processor and a memory;
[0014] The memory stores computer-executable instructions;
[0015] The processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the inter-process data transmission method described in the first aspect and various possible designs of the first aspect.
[0016] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the inter-process data transmission method described in the first aspect and various possible designs of the first aspect is implemented.
[0017] In a fifth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which, when executed by a processor, implements the inter-process data transmission method described in the first aspect and various possible designs of the first aspect.
[0018] The inter-process data transmission method, device, electronic device and storage medium provided in this embodiment, after creating a local inter-process communication connection for a first program process and a second program process, obtain a data flow identifier through the first program process; write target data to the data buffer area of the shared memory through the first program process, and after the target data is written, write a first read-write status value to the target position of the first bitmap field of the shared memory based on the data flow identifier, and the target position is determined based on the data flow identifier; the second program process performs a busy wait polling detection on the first bitmap field of the shared memory, and if the first read-write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data buffer area. After the first program process writes the target data to be sent to the shared memory, the first read-write status value is written to the specified position of the first bitmap field in the shared memory to trigger the data acquisition operation of the second program process, thereby realizing the sending of data, and the process does not require a system call, thereby saving the resource overhead of the system call, improving the efficiency of data transmission, and reducing waiting delay. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0020] Figure 1 An application scenario diagram of the inter-process data transmission method provided in the embodiment of the present disclosure;
[0021] Figure 2 A schematic diagram of a process for inter-process data transmission using shared memory provided in an embodiment of the present disclosure;
[0022] Figure 3 Schematic diagram of the process of the inter-process data transmission method provided in the embodiment of the present disclosure Figure 1 ;
[0023] Figure 4 for Figure 3 A flowchart of a specific implementation method of step S101 in the illustrated embodiment;
[0024] Figure 5 for Figure 3 A flowchart of a specific implementation method of step S102 in the illustrated embodiment;
[0025] Figure 6 A schematic diagram of a shared memory provided in an embodiment of the present disclosure;
[0026] Figure 7 A schematic diagram of a bitmap field to a shared memory provided by an embodiment of the present disclosure;
[0027] Figure 8 Schematic diagram of the process of the inter-process data transmission method provided in the embodiment of the present disclosure Figure 2 ;
[0028] Fig. 9 for Figure 8 A flowchart of a specific implementation method of step S209 in the illustrated embodiment;
[0029] Fig.10 A structural block diagram of an inter-process data transmission device provided in an embodiment of the present disclosure;
[0030] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure;
[0031] Fig.12 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0032] In order to make the purpose, technical solution and advantages of the embodiments of the present disclosure clearer, the technical solution in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present disclosure.
[0033] 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 disclosure 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 the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0034] The application scenarios of the embodiments of the present disclosure are explained below:
[0035] Figure 1 An application scenario diagram of the inter-process data transmission method provided in the embodiment of the present disclosure. The inter-process data transmission method provided in the embodiment of the present disclosure can be applied to a data processor (Data Processing Unit, DPU) chip, or a smart computing card containing a data processor chip. More specifically, it can be applied to the process of controlling information interaction between local application processes in a host machine (Host) in a virtual machine application scenario. The executor of this embodiment can be a virtual machine server (i.e., a host machine) equipped with a smart computing card or a data processor chip, or other electronic devices that perform similar functions. Reference Figure 1 As shown in , taking a virtual machine server as an example, the virtual machine server creates multiple clients (guests) through virtualization technology, and supports the operation of the clients through its own computing resources. Furthermore, a smart computing card containing a data processor chip is mounted on the virtual machine server. In the smart computing card, a data plane program for executing data processing tasks and multiple applications corresponding to the client are running. When the client needs to execute a function of the application, the smart computing card controls the application to establish process communication with the data plane program, and realizes data transmission through shared memory. The data plane program in the smart computing card completes the data processing process and returns the processing results to the application.
[0036] In the related art, by utilizing the Unix Domain Socket (UDS) protocol implemented based on the Socket interface under the Linux system, local inter-process communication based on UDS messages can be implemented. Figure 2 A schematic diagram of a process of using shared memory to perform inter-process data transmission is provided in an embodiment of the present disclosure, such as Figure 2 As shown, exemplarily, the application corresponds to the first program process, the second program process corresponding to the data plane program, and the first program process and the second program process are both provided by a data processor (DPU). Specifically, the main steps include: first, the first program process creates a UDS service (UDS server) by calling a nested word interface, and monitors the specified address of the shared memory; the second program process creates a UDS nested word object (UDS socket) with a nested word interface, connects the specified address monitored by the first program process, and thus creates a UDS connection (connection). Afterwards, when the first program process needs to send data, the data is written to the shared memory, and then a notification message is sent through the UDS connection. After the second program process receives the notification message, it reads the data from the shared memory, and after completion, returns a response message to the first program process to notify the first program process that the data has been received (by the second program process). Further, after the first program process receives the response message, it continues to execute the next round of data transmission.
[0037] Taking the above-mentioned related technology as an example, in the process of data transmission between local processes between applications and data plane programs with the help of shared memory, different application processes usually transmit notification messages and response messages through system calls (syscall) after writing the data to be transmitted into the shared memory. This results in that each time a notification message is sent on one side, it is necessary to wait for the other side to return the response information received before executing the next step, which leads to line congestion and low thread utilization, and further leads to low data transmission efficiency and high latency in the data transmission process between threads.
[0038] The embodiment of the present disclosure provides an inter-process data transmission method to solve the above-mentioned problem.
[0039] refer to Figure 3 , Figure 3 Schematic diagram of the process of the inter-process data transmission method provided in the embodiment of the present disclosure Figure 1 The method of this embodiment can be applied in a smart computing card. The inter-process data transmission method includes:
[0040] Step S101: After a first program process establishes a local inter-process communication connection with a second program process, a data flow identifier is obtained through the first program process.
[0041] For example, reference Figure 1 The application scenario diagram and Figure 2 In the process diagram shown, the first program process is, for example, a process corresponding to an application program, and the second program process is, for example, a process corresponding to a data plane program that implements a certain data processing function. First, the first program process and the second program process running in the smart computing card are connected to a local inter-process communication connection based on a local inter-process communication protocol, such as a UDS protocol, and after the local inter-process communication connection is established, an initialization handshake is performed, so that the first program process obtains a data flow identifier, and the data flow identifier corresponds to a subsequent data flow transmission task to be executed.
[0042] The following first introduces the process of creating a local inter-process communication connection between the first program process and the second program process. For example, first, the first program process creates a memory file descriptor (memfd) by calling the shm_open method in the Linux system, and calls the mmap method based on the memory file descriptor to map a piece of shared memory. After that, the first program process creates a UDS service by calling the nested word interface and monitors the specified address of the shared memory; the second program process uses the nested word interface to create a UDS nested word object, connects to the specified address monitored by the first program process, and thus creates a UDS connection. After the UDS connection is created, the first application process sends the memory file descriptor through the UDS connection, and the second application process calls the mmap method based on the memory file descriptor to map the same shared memory after receiving it.
[0043] Further, after the first program process and the second program process establish a local inter-process communication connection, an initial handshake is performed on the first program process and the second program process, so that the first program process obtains a data flow identifier. Figure 4 As shown, the specific implementation method of obtaining the data flow identifier through the first program process in step S101 includes:
[0044] Step S1011: The first program process sends a handshake request message to the second program process through a local inter-process communication connection, where the handshake request message is used to register a data stream transmission task on the second program process side.
[0045] Step S1012: The handshake request message is processed by the second program process to generate a handshake response message, and the handshake response message is returned to the first program process. The handshake response message includes a data stream identifier corresponding to the data stream transmission task.
[0046] Step S1013: Receive a handshake response message through the first program process to obtain a data flow identifier.
[0047] Exemplarily, first, the first program process sends a handshake request message to the second program process through the previously established local inter-process communication connection (i.e., UDS connection). After receiving the handshake request message, the second program process reads the information in the handshake request message and performs application processing to register the data stream transmission task. Specifically, the second program process processes the information in the handshake request message and registers the specific method of the data stream transmission task, for example, including: the handshake request message declares a number of message fields and variables related to the first program process and / or the data stream transmission task to be executed, and then the second program process fills in the corresponding control information based on the message field in the above-mentioned handshake request message, generates a response message, and completes the configuration of the data stream transmission task at the same time, thereby achieving the purpose of registering the data stream transmission task. The response message contains a data stream identifier corresponding to the data stream transmission task, which is used to indicate the data stream of the target data submitted by the first program process to the second program process for processing in the data stream transmission task.
[0048] Furthermore, the second program process returns a handshake response message including a data flow identifier to the first program process. After receiving the handshake response message, the first program process parses it and obtains the data flow identifier. At this point, the initialization handshake process ends, and the first program process obtains a data flow identifier returned by the second program process. Subsequently, shared memory reading and writing are performed based on the data flow identifier. Since shared memory reading and writing based on the data flow identifier utilizes the mapping relationship between the data flow identifier and the data flow transmission task, parallel data transmission in units of data flow is realized, thereby improving data transmission efficiency.
[0049] Furthermore, the handshake request message and the handshake response message may also include other information required for registering the data stream transmission task. For example, the handshake request message includes a first request field and / or a second request field. The first request field is used to determine the program version information of the second program process adapted to the first program process; the second request field is used to characterize the memory space required for the data stream transmission task.
[0050] Specifically, for example, the first request field specifies the application corresponding to the first application process, and the version number of the data plane program corresponding to the second application process that needs to be used to ensure compatibility. After the control plane message of the data plane program is updated, the new processing logic uses the new version number. If the application uses the old version number, the data plane program will also use the processing logic of the data plane program corresponding to the old version number. The second request field specifies the size of shared memory that the application needs to use. The data plane program will allocate the corresponding size of shared memory to it according to the value recorded in this field.
[0051] For another example, the handshake response message also includes at least one of the following: a first response field, used to indicate the maximum concurrency of the second program process executing the data stream transmission task; a second response field, used to indicate the memory capacity of the shared memory; a third response field, used to indicate the bitmap field in the shared memory corresponding to the data stream transmission task.
[0052] Specifically, the first response field is used to indicate the maximum concurrency of the data plane program processing the data flow. When the maximum concurrency is exceeded, the data access request of the application program is queued; the second response field is used to indicate the memory capacity of the shared memory used to write the target data, and the single data transmission volume cannot exceed the memory capacity; the third response field is used to indicate the position of the bitmap field in the shared memory corresponding to the data flow transmission task this time, wherein the bitmap field includes multiple types, such as the first bitmap field for storing the read-write status, the second bitmap field for the closed status, etc. The specific role of the bitmap field is described in detail in the subsequent embodiment section.
[0053] In addition, the handshake response message may also include a version field corresponding to the first request field, and the field value is consistent with the version number requested by the first request field; a status field, which represents the result of processing the handshake request message. Specifically, if no error occurs during normal processing, the field value of the status field is set to 0; if an error occurs, the field value of the status field is set to the corresponding error code, and so on. The specific settings can be made as needed and will not be repeated here.
[0054] Step S102: write target data to the data buffer area of the shared memory through the first program process, and after the target data is written, write a first read-write status value to the target position of the first bitmap field of the shared memory based on the data stream identifier, and the target position is determined based on the data stream identifier.
[0055] Exemplarily, after the initialization handshake is completed, the first program process writes the target data to the data buffer of the shared memory, that is, the data stream corresponding to the data stream identifier. At the same time, in the process of writing the target data, it is necessary to ensure that the maximum data length specified during the initialization handshake is not exceeded. The maximum data length is determined based on the field value of the second response field of the handshake response message. For details, please refer to the introduction of the previous steps.
[0056] Furthermore, in a possible implementation, Figure 5 As shown, the specific implementation of step S102 includes:
[0057] Step S1021: Obtain the offset address of the data buffer area.
[0058] Step S1022: determine the data buffer area according to the offset address, and write the target data into the data buffer area.
[0059] Exemplarily, in the process of writing target data to the data buffer area of shared memory, the first program process first needs to determine the offset address of the data buffer area, i.e., the buffer area offset address (buffer_offset). The buffer area offset address is determined by the second program process during the initialization handshake and is written in the handshake response message, and sent to the first program process. The first program process obtains the buffer area offset address based on the field value of the address field in the handshake response message. Afterwards, based on the buffer area offset address and the starting address of the shared memory, the memory access address of the data buffer area is determined, and then based on the memory access address, the target data is written.
[0060] Furthermore, after the target data is written into the data cache, in order to ensure that the second program process can accurately read the target data from the data cache, it is necessary to ensure that the second program process can determine the data length of the target data. In a possible implementation, the method of this embodiment also includes: the first program process obtains the data length (data_len) of the target data, and writes the data length into a data length field before the data cache. The data length field may have a fixed automatic length, such as k bits, so after obtaining the offset address of the data cache, the position of the data length field may be obtained by calculation; or, the offset address of the data cache points to the data length field, and after the data length field, the data cache is immediately followed.
[0061] Figure 6 A schematic diagram of a shared memory provided by an embodiment of the present disclosure, such as Figure 6 As shown, in the shared memory, a continuous first bitmap field, a second bitmap field, and a third bitmap field are provided, and after the third bitmap field, a continuous data length field and a data buffer area are provided at intervals. Wherein, the bitmap field has a fixed length, for example, N bits (bit), N is the number of the first program process communicating with the second program process, or, is the maximum concurrency of the second program process. The bitmap field is located by the bitmap offset address, and the total length of the data length field and the data buffer area is the buffer length, and the data length field is located by the buffer area offset address. The above-mentioned bitmap offset address, buffer area offset address, bitmap field length, data length field length, buffer length and other information are all recorded in the handshake response message, and the first program can be obtained by the handshake response message.
[0062] Through the scheme of the steps of this embodiment, in the subsequent steps, the second program process can determine the data length of the target data by accessing the data length field, thereby quickly reading the target data from the data buffer area, thereby improving the efficiency of data processing.
[0063] After that, after the target data is written, the first program process continues to write the first read-write status value to the target position of the first bitmap field of the shared memory, wherein the bitmap is a specific space in the shared memory, and there are multiple bitmap fields in the shared memory, such as the first bitmap field mentioned in the steps of this embodiment, and the second bitmap field mentioned in the subsequent embodiments, and so on. Among them, each bitmap field is composed of multiple bits, and each bit can store a binary number, that is, 0 or 1. Further, the first bitmap field is an area for storing read-write status, and the first read-write status value written to the first bitmap field, for example, is 1, indicating that the first program process has written the target data to the data cache area of the shared memory. Correspondingly, if the second read-write status value written to the first bitmap field is 0, it indicates that there is no valid data in the data cache area. Of course, the first read-write status value and the second read-write status value can also be opposite, for example, the first read-write status value is 0, and the second read-write status value is 1, which can be set as needed. Afterwards, the second program process can detect the target position and determine whether to read data from the data cache area according to whether the state value at the target position is the first read-write state value or the second read-write state value, thereby achieving accurate transmission of the target data.
[0064] Figure 7 A schematic diagram of a bitmap field to a shared memory provided by an embodiment of the present disclosure, such as Figure 7 As shown, exemplarily, at the bitmap offset address (bitmap_offset) position of the shared memory, a first bitmap field is set, and the bitmap field is composed of N bits, wherein each bit corresponds to a data stream (data stream identifier). The nth bit in the first bitmap field is the target position corresponding to the data stream identifier n. The first program process determines the target position as bitmap_offset+n based on the bitmap offset address and the data stream identifier n, and then writes the first read-write state value (shown as 1 in the figure) to the target position of the shared memory.
[0065] Step S103: The second program process performs busy-wait polling detection on the first bitmap field of the shared memory. If a first read / write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data buffer.
[0066] Exemplarily, after the first program process writes the target data into the data cache area and writes the status value into the target position of the first bitmap field, the second program process monitors the first bitmap field by busy-polling, that is, monitors all bits of the first bitmap field to obtain the status value of each bit of the first bitmap field in real time. Since, by default, for example, after the initialization handshake is completed, the status value of each bit in the first bitmap field is the second read-write status value (for example, 0), the second program process will detect the second read-write status value at the target position of the first bitmap field. In this case, the second program process will continue to monitor by busy-polling, but will not read data from the data cache area; until the second program process detects the first read-write status value (for example, 1) at the target position of the first bitmap field, the second program process is equivalent to receiving a task request, at which time, the second program process reads the target data from the data cache area, which is the data to be processed, that is, the target data output by the first program process. Thus, the data interaction between the first program process and the second program process is completed.
[0067] Furthermore, the second program process obtains the target data length corresponding to the data flow identifier from the data length field of the shared memory by reading the data length field of the shared memory, and then accurately reads the corresponding data, i.e., the target data, from the data cache area based on the target data length.
[0068] In the disclosed embodiment, after a local inter-process communication connection is created between a first program process and a second program process, a data flow identifier is obtained through the first program process; the target data is written to the data buffer area of the shared memory through the first program process, and after the target data is written, a first read-write status value is written to the target position of the first bitmap field of the shared memory based on the data flow identifier, and the target position is determined based on the data flow identifier; the second program process performs a busy wait polling detection on the first bitmap field of the shared memory, and if the first read-write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data buffer area. After the first program process writes the target data to be sent to the shared memory, the first read-write status value is written to the specified position of the first bitmap field in the shared memory to trigger the data acquisition operation of the second program process, thereby realizing the sending of data, and the process does not require a system call, thereby saving the resource overhead of the system call, improving the efficiency of data transmission, and reducing waiting delays.
[0069] refer to Figure 8 , Figure 8 Schematic diagram of the process of the inter-process data transmission method provided in the embodiment of the present disclosure Figure 2 In this embodiment Figure 2On the basis of the embodiment shown, further processing steps after the process is disconnected are added, and the inter-process data transmission method includes:
[0070] Step S201: After a local inter-process communication connection is created between a first program process and a second program process, a data flow identifier is obtained through the first program process.
[0071] Step S202: write target data to the data buffer area of the shared memory through the first program process, and after the target data is written, write a first read-write status value to the target position of the first bitmap field of the shared memory based on the data stream identifier, and the target position is determined based on the data stream identifier.
[0072] Step S203: The second program process performs busy-wait polling detection on the first bitmap field of the shared memory. If a first read / write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data buffer.
[0073] Step S204: If neither the first program process nor the second program process reaches the stop condition, return to step S201; otherwise, execute step S205 or step S207.
[0074] Step S205: After the first program process reaches the stop condition, close the local inter-process communication connection on the first program process side.
[0075] Step S206: When the second program process monitors that the first program process closes the local inter-process communication connection, the local inter-process communication connection on the second program process side is closed.
[0076] Exemplarily, the stop condition of the first program process referred to in the steps of this embodiment includes the abnormal termination of the first program process or the closing of the first program process in response to an instruction, wherein the closing of the first program process in response to an instruction includes closing in response to a user instruction, or closing based on program logic, such as when the application has no data transmission requirements and after the data transmission task is completed, executing a closing instruction to end the first program process, etc., which will not be repeated here. Afterwards, if the first program process reaches the stop condition, the local inter-process communication connection on the first program process side is closed, such as including closing the UDS connection, closing the notification event file descriptor, etc. Among them, the notification event file descriptor (notify eventfd) is an event file descriptor (eventfd) for notifying the first program process that the second program process has completed data transmission. After the second program process completes the data stream transmission task, it will convey the message of the completion of data transmission to the first program process by writing the notification event file descriptor.
[0077] Further, since a shared memory is occupied between the first program process and the second program process to realize the local inter-process communication connection, if the first program process reaches the stop condition and closes the local inter-process communication connection on the first program process side, but the second program process is still running, it is necessary to trigger the second program process to close the local inter-process communication connection. Specifically, after the first program process closes the local inter-process communication connection (UDS connection), the second program process listens to the EPOLLHUP event by calling the epoll_wait method. In this case, the second program process performs a complete data stream release operation. Since the second program process does not need to delay the disconnection operation after the first program process is disconnected, the implementation method of closing the local inter-process communication connection on the second program process side includes: executing the first release step and the second release step in sequence to close the local inter-process communication connection on the second program process side. Wherein, the first release step is used to write a notification event file descriptor, and then close the notification event file descriptor, and the notification event file descriptor is used to notify the first program process that the second program process data transmission is complete. The second release step is used to set the data of the target position of all bitmap fields to the second state value, and clean up the relevant resources of the data stream.
[0078] Specifically, the step of closing the local inter-process communication connection on the second program process side includes executing in sequence: writing a notification event file descriptor, closing the notification event file descriptor, setting the nth bit of all bitmap fields (i.e., the data flow identifier corresponding to the first program process) to 0, that is, restoring all bitmap fields related to the current data flow identifier in the shared memory to the default state; then cleaning up other related resources for processing the data flow, thereby closing the UDS connection.
[0079] After the first program process closes the UDS connection, the second program process is still writing data streams to the data buffer area. Since the shared memory is still held by the second program process, there will be no error in writing to the shared memory. At the same time, the data buffer area of the shared memory still belongs to the data stream for the second program process, and no exception will occur. Afterwards, after the second program process finishes writing to the data buffer area, it will monitor the EPOLLHUP event through epoll_wait, and learn that the first program process is closed, so as to perform the data stream release step, which will not cause errors and exceptions.
[0080] Furthermore, after the first program process reaches the closing condition, it also includes: writing the first application closing state value to the target position of the second bitmap field of the shared memory through the first program process; the first application closing state value is used to trigger the closing of the local inter-process communication connection of the second program process. Specifically, in one possible implementation, when the second program process is in a waiting state, when the first application closing state value (for example, 1) of the target position of the second bitmap field is detected, the waiting state will end, and the local inter-process communication connection on the second program process side will be closed, specifically, for example, the second release step in the above embodiment is executed. Thereby triggering the closing of the local inter-process communication connection of the second program process.
[0081] Step S207: After the second program process reaches the stop condition, the connection status of the local inter-process communication connection of the first program process is obtained.
[0082] Step S208: If the local inter-process communication connection of the first program process is closed, the local inter-process communication connection on the second program process side is directly closed.
[0083] Step S209: If the local inter-process communication connection of the first program process is not closed, the closing of the local inter-process communication connection of the first program process is triggered, and the second program process is set to a waiting state for closing until the local inter-process communication connection of the first program process is closed, and then the local inter-process communication connection on the second program process side is closed.
[0084] In another possible situation, when the second program process reaches the stop condition, the local inter-process communication connection on the second program process side is not directly closed, but the connection status of the local inter-process communication connection of the first program process is first obtained for judgment. If the local inter-process communication connection of the first program process is closed according to the connection status, the local inter-process communication connection on the second program process side is directly closed. The implementation method of this situation is similar to the implementation method of step S206, which will not be repeated; and if the local inter-process communication connection of the first program process is not closed according to the connection status, the closing of the local inter-process communication connection of the first program process is first triggered, and the second program process is set to the waiting closing state to avoid the problem that the first program is still writing data to the shared memory, and the second program process has been disconnected, resulting in a shared memory write error. Afterwards, until the local inter-process communication connection of the first program process is closed, the closing step of the local inter-process communication connection on the second program process side is executed.
[0085] Specifically, Fig. 9 As shown, the specific implementation of step S209 includes:
[0086] Step S2091: If the local inter-process communication connection of the first program process is not closed, the first service closing state value is written to the target position of the second bitmap field of the shared memory through the second program process.
[0087] Step S2092: Set the second program process to a waiting-to-close state.
[0088] Step S2093: When the first program process detects that the target position of the second bitmap field of the shared memory is the first service shutdown state value, a stop condition for closing the local inter-process communication connection is triggered.
[0089] Step S2094: the first program process writes the first application closing status value to the target location of the third bitmap field of the shared memory.
[0090] Step S2095: When the second program process detects that the target position of the third bitmap field of the shared memory is the first application closed state value, or exceeds a preset time, the local inter-process communication connection on the second program process side is closed.
[0091] Among them, exemplarily, first, the target position corresponds to the data flow identifier, which is used to indicate the position in the bitmap field corresponding to the currently processed data flow (data flow transmission task) in the same meaning as in the previous embodiment steps. The second bitmap field is a bitmap field used to record the service shutdown status (corresponding to the data plane program) of the second application thread. When the field value of the second bitmap field is the first service shutdown status value (for example, 1), it indicates that the local inter-process communication of the second application thread has been disconnected or needs to be disconnected. After the second program process writes the first service shutdown status value to the target position of the second bitmap field of the shared memory, the first program process will monitor the target position of the second bitmap field. After monitoring the first service shutdown status value, the stop condition for closing the local inter-process communication connection is triggered, thereby executing the step of closing the local inter-process communication connection on the first program process side in the above embodiment steps (step S205). Afterwards, the first program process writes the first application closing state value to the target position of the third bitmap field of the shared memory. The third bitmap field is a bitmap field used to record the application closing state (corresponding to the application) of the first application thread. When the first application closing state value (e.g., 1) is written to the target position of the third bitmap field, it indicates that the local inter-process communication of the first program process has been disconnected or needs to be disconnected. Correspondingly, after the second program monitors that the target position of the third bitmap field is the first application closing state value, it switches from the current waiting closing state to the execution state, and executes the step of closing the local inter-process communication connection on the second program process side. Optionally, after switching to the execution state, the second program process executes the second release step in the above embodiment, and the first release step is executed synchronously when step S2091 is executed, that is, while the second program process writes the first service closing state value to the target position of the second bitmap field of the shared memory, it writes the notification event file descriptor, and then closes the notification event file descriptor.
[0092] In this embodiment, the closing status of the first program process and the second program process is marked by combining the second bitmap field and the third bitmap field, so that after one of the first program process and the second program process disconnects the local inter-process communication connection, the other is triggered to execute the step of disconnecting the local inter-process communication connection, and by setting the waiting closing status for the second program process, the priority disconnection of the first program process is guaranteed, thereby avoiding write errors in the shared memory and improving the stability of the system.
[0093] In this embodiment, the implementation method of steps S201 to S203 is the same as that of the present disclosure. Figure 2 The implementation methods of step S101 to step S103 in the illustrated embodiment are the same and will not be described in detail here.
[0094] Corresponding to the inter-process data transmission method of the above embodiment, Fig.10This is a structural block diagram of an inter-process data transmission device provided by an embodiment of the present disclosure. For ease of explanation, only the parts related to the embodiment of the present disclosure are shown. Fig.10 , the inter-process data transmission device 3 comprises:
[0095] An acquisition module 31, configured to obtain a data flow identifier through the first program process after establishing a local inter-process communication connection between the first program process and the second program process;
[0096] A writing module 32, used for writing target data to the data buffer area of the shared memory through the first program process, and after the target data is written, writing a first read-write state value to a target position of the first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier;
[0097] The reading module 33 is used to perform busy waiting polling detection on the first bitmap field of the shared memory through the second program process, and if the first read / write state value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data buffer area.
[0098] According to one or more embodiments of the present disclosure, when the acquisition module 31 obtains the data flow identifier through the first program process, it is specifically used to: the first program process sends a handshake request message to the second program process through a local inter-process communication connection, and the handshake request message is used to register the data flow transmission task on the second program process side; the handshake request message is processed by the second program process, and a handshake response message is generated and returned to the first program process, and the handshake response message includes the data flow identifier corresponding to the data flow transmission task; the handshake response message is received by the first program process to obtain the data flow identifier.
[0099] According to one or more embodiments of the present disclosure, the handshake request message includes a first request field and / or a second request field, the first request field is used to determine the program version information of the second program process adapted by the first program process; the second request field is used to characterize the memory space required for the data stream transmission task.
[0100] According to one or more embodiments of the present disclosure, the handshake response message also includes at least one of the following: a first response field, used to indicate the maximum concurrency of the second program process executing the data stream transmission task; a second response field, used to indicate the memory capacity of the shared memory; a third response field, used to indicate the bitmap field in the shared memory corresponding to the data stream transmission task.
[0101] According to one or more embodiments of the present disclosure, when the write module 32 writes target data to the data cache area of the shared memory through the first program process, it is specifically used to: obtain the offset address of the data cache area; determine the data cache area according to the offset address, and write the target data to the data cache area.
[0102] According to one or more embodiments of the present disclosure, the write module 32 is also used to: obtain the data length of the target data; write the data length into the data length field before the data cache; the read module 33 obtains the target data output by the first program process from the data cache, including: obtaining the target data length corresponding to the data flow identifier from the data length field of the shared memory; based on the target data length, read the data cache to obtain the target data.
[0103] According to one or more embodiments of the present disclosure, the write module 32 is further used to: after the first program process reaches a stop condition, close the local inter-process communication connection on the first program process side; the read module 33 is further used to: when the second program process monitors that the first program process closes the local inter-process communication connection, close the local inter-process communication connection on the second program process side.
[0104] According to one or more embodiments of the present disclosure, when closing the local inter-process communication connection on the second program process side, the reading module 33 is specifically used to: execute a first release step and a second release step in sequence to close the local inter-process communication connection on the second program process side; wherein the first release step is used to write a notification event file descriptor and then close the notification event file descriptor, and the notification event file descriptor is used to notify the first program process that the data transmission between the second program process is completed; the second release step is used to set the data at the target position of all bitmap fields to a second state value, and clean up related resources of the data stream.
[0105] According to one or more embodiments of the present disclosure, before closing the local inter-process communication connection on the first program process side, the write module 32 is also used to: write a first application closing status value to the target location of the second bitmap field of the shared memory through the first program process; the first application closing status value is used to trigger the closing of the local inter-process communication connection of the second program process.
[0106] According to one or more embodiments of the present disclosure, the reading module 33 is also used to: obtain the connection status of the local inter-process communication connection of the first program process after the second program process reaches the stop condition; if the local inter-process communication connection of the first program process is closed, directly close the local inter-process communication connection on the second program process side; if the local inter-process communication connection of the first program process is not closed, trigger the closing of the local inter-process communication connection of the first program process, and set the second program process to a waiting state until the local inter-process communication connection of the first program process is closed, and then close the local inter-process communication connection on the second program process side.
[0107] According to one or more embodiments of the present disclosure, when the reading module 33 triggers the closing of the local inter-process communication connection of the first program process, it is specifically used to: write the first service closing status value to the target position of the second bitmap field of the shared memory through the second program process; when the first program process detects that the target position of the second bitmap field of the shared memory is the first service closing status value, it triggers the stop condition for closing the local inter-process communication connection, and writes the first application closing status value to the target position of the third bitmap field of the shared memory; when the reading module 33 closes the local inter-process communication connection on the second program process side after the local inter-process communication connection of the first program process is closed, it is specifically used to: when the second program process detects that the target position of the third bitmap field of the shared memory is the first application closing status value, or after exceeding a preset time, close the local inter-process communication connection on the second program process side.
[0108] The acquisition module 31, the writing module 32 and the reading module 33 are connected in sequence. The inter-process data transmission device 3 provided in this embodiment can implement the technical solution of the above method embodiment, and its implementation principle and technical effect are similar, which will not be repeated in this embodiment.
[0109] Fig.11 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure is shown in FIG. Fig.11 As shown, the electronic device 4 includes:
[0110] A processor 41, and a memory 42 communicatively connected to the processor 41;
[0111] The memory 42 stores computer executable instructions;
[0112] The processor 41 executes the computer execution instructions stored in the memory 42 to implement the following Figure 2-Figure 9 The inter-process data transmission method in the illustrated embodiment.
[0113] Optionally, the processor 41 and the memory 42 are connected via a bus 43 .
[0114] For related instructions, please refer to Figure 2-Figure 9 The relevant descriptions and effects corresponding to the steps in the corresponding embodiments can be understood, and no further elaboration is made here.
[0115] The present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions, which are used to implement the present invention when executed by a processor. Figure 2-Figure 9 The inter-process data transmission provided by any one of the corresponding embodiments.
[0116] The present invention provides a computer program product, including a computer program. When the computer program is executed by a processor, the present invention is realized. Figure 2-Figure 9 The inter-process data transmission provided by any one of the corresponding embodiments.
[0117] In order to implement the above embodiment, the embodiment of the present disclosure also provides an electronic device.
[0118] refer to Fig.12 , which shows a schematic diagram of the structure of an electronic device 900 suitable for implementing the embodiment of the present disclosure, and the electronic device 900 may be a terminal device or a server. The terminal device may include but is not limited to mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (Portable Android Devices, PADs), portable multimedia players (PMPs), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig.12 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0119] like Fig.12 As shown, the electronic device 900 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage device 908 to a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the electronic device 900 are also stored. The processing device 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0120] Typically, the following devices may be connected to the I / O interface 905: input devices 906 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 908 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or by wire to exchange data. Although Fig.12 The electronic device 900 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0121] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 909, or installed from a storage device 908, or installed from a ROM 902. When the computer program is executed by the processing device 901, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0122] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0123] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0124] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device executes the method shown in the above embodiment.
[0125] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0126] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0127] The modules involved in the embodiments described in the present disclosure may be implemented by software or hardware, wherein the name of a module does not, in some cases, limit the module itself.
[0128] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0129] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0130] In a first aspect, according to one or more embodiments of the present disclosure, a method for transmitting data between processes is provided, including:
[0131] After a local inter-process communication connection is created between a first program process and a second program process, a data flow identifier is obtained through the first program process; target data is written to a data cache area of a shared memory through the first program process, and after the target data is written, a first read-write status value is written to a target position of a first bitmap field of the shared memory based on the data flow identifier, and the target position is determined based on the data flow identifier; a busy wait polling detection is performed on the first bitmap field of the shared memory through the second program process, and if the first read-write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data cache area.
[0132] According to one or more embodiments of the present disclosure, obtaining the data flow identifier through the first program process includes: the first program process sends a handshake request message to the second program process through the local inter-process communication connection, and the handshake request message is used to register a data flow transmission task on the second program process side; the second program process processes the handshake request message, generates a handshake response message, and returns it to the first program process, and the handshake response message includes the data flow identifier corresponding to the data flow transmission task; and the first program process receives the handshake response message to obtain the data flow identifier.
[0133] According to one or more embodiments of the present disclosure, the handshake request message includes a first request field and / or a second request field, the first request field is used to determine the program version information of the second program process adapted by the first program process; the second request field is used to characterize the memory space required for the data stream transmission task.
[0134] According to one or more embodiments of the present disclosure, the handshake response message also includes at least one of the following: a first response field, used to indicate the maximum concurrency of the second program process in executing the data stream transmission task; a second response field, used to indicate the memory capacity of the shared memory; and a third response field, used to indicate a bitmap field in the shared memory corresponding to the data stream transmission task.
[0135] According to one or more embodiments of the present disclosure, writing the target data to the data cache area of the shared memory through the first program process includes: obtaining an offset address of the data cache area; determining the data cache area according to the offset address, and writing the target data to the data cache area.
[0136] According to one or more embodiments of the present disclosure, the method also includes: obtaining the data length of the target data; writing the data length into a data length field before the data cache; obtaining the target data output by the first program process from the data cache, including: obtaining the target data length corresponding to the data flow identifier from the data length field of the shared memory; based on the target data length, reading the data cache to obtain the target data.
[0137] According to one or more embodiments of the present disclosure, the method also includes: after the first program process reaches a stop condition, closing the local inter-process communication connection on the first program process side; when the second program process monitors that the first program process closes the local inter-process communication connection, closing the local inter-process communication connection on the second program process side.
[0138] According to one or more embodiments of the present disclosure, closing the local inter-process communication connection on the second program process side includes: executing a first release step and a second release step in sequence to close the local inter-process communication connection on the second program process side; wherein the first release step is used to write a notification event file descriptor and then close the notification event file descriptor, and the notification event file descriptor is used to notify the first program process that the data transmission of the second program process is completed; the second release step is used to set the data at the target position of all bitmap fields to a second state value, and clean up related resources of the data stream.
[0139] According to one or more embodiments of the present disclosure, before closing the local inter-process communication connection on the first program process side, it also includes: writing a first application closing status value to the target location of the second bitmap field of the shared memory through the first program process; the first application closing status value is used to trigger the closing of the local inter-process communication connection of the second program process.
[0140] According to one or more embodiments of the present disclosure, the method also includes: after the second program process reaches the stop condition, obtaining the connection status of the local inter-process communication connection of the first program process; if the local inter-process communication connection of the first program process is closed, directly closing the local inter-process communication connection on the second program process side; if the local inter-process communication connection of the first program process is not closed, triggering the closing of the local inter-process communication connection of the first program process, and setting the second program process to a waiting state until the local inter-process communication connection of the first program process is closed, and then closing the local inter-process communication connection on the second program process side.
[0141] According to one or more embodiments of the present disclosure, the triggering of closing the local inter-process communication connection of the first program process includes: writing a first service closing status value to a target position of a second bitmap field of the shared memory through the second program process; when the first program process detects that the target position of the second bitmap field of the shared memory is the first service closing status value, triggering a stop condition for closing the local inter-process communication connection, and writing a first application closing status value to a target position of a third bitmap field of the shared memory; until the local inter-process communication connection of the first program process is closed, then closing the local inter-process communication connection on the second program process side includes: when the second program process detects that the target position of the third bitmap field of the shared memory is the first application closing status value, or after a preset time period has expired, closing the local inter-process communication connection on the second program process side.
[0142] In a second aspect, according to one or more embodiments of the present disclosure, there is provided an inter-process data transmission device, comprising:
[0143] an acquisition module, configured to obtain a data flow identifier through the first program process after establishing a local inter-process communication connection between the first program process and the second program process;
[0144] A writing module, used for writing target data to a data buffer area of a shared memory through the first program process, and after the target data is written, writing a first read-write status value to a target position of a first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier;
[0145] The reading module is used to perform busy-wait polling detection on the first bitmap field of the shared memory through the second program process, and if the first read-write status value is detected at the target position of the first bitmap field, the target data output by the first program process is obtained from the data cache area.
[0146] According to one or more embodiments of the present disclosure, when the acquisition module obtains the data flow identifier through the first program process, it is specifically used to: the first program process sends a handshake request message to the second program process through the local inter-process communication connection, and the handshake request message is used to register the data flow transmission task on the side of the second program process; the second program process processes the handshake request message, generates a handshake response message, and returns it to the first program process, and the handshake response message includes the data flow identifier corresponding to the data flow transmission task; the first program process receives the handshake response message to obtain the data flow identifier.
[0147] According to one or more embodiments of the present disclosure, the handshake request message includes a first request field and / or a second request field, the first request field is used to determine the program version information of the second program process adapted by the first program process; the second request field is used to characterize the memory space required for the data stream transmission task.
[0148] According to one or more embodiments of the present disclosure, the handshake response message also includes at least one of the following: a first response field, used to indicate the maximum concurrency of the second program process to execute the data stream transmission task; a second response field, used to indicate the memory capacity of the shared memory; a third response field, used to indicate the bitmap field in the shared memory corresponding to the data stream transmission task.
[0149] According to one or more embodiments of the present disclosure, when the write module writes target data to the data cache area of the shared memory through the first program process, it is specifically used to: obtain the offset address of the data cache area; determine the data cache area according to the offset address, and write the target data to the data cache area.
[0150] According to one or more embodiments of the present disclosure, the write module is also used to: obtain the data length of the target data; write the data length into the data length field before the data cache area; the read module obtains the target data output by the first program process from the data cache area, including: obtaining the target data length corresponding to the data flow identifier from the data length field of the shared memory; based on the target data length, read the data cache area to obtain the target data.
[0151] According to one or more embodiments of the present disclosure, the write module is further used to: after the first program process reaches a stop condition, close the local inter-process communication connection on the first program process side; the read module is further used to: when the second program process monitors that the first program process closes the local inter-process communication connection, close the local inter-process communication connection on the second program process side.
[0152] According to one or more embodiments of the present disclosure, when closing the local inter-process communication connection on the second program process side, the reading module is specifically used to: execute a first release step and a second release step in sequence to close the local inter-process communication connection on the second program process side; wherein the first release step is used to write a notification event file descriptor and then close the notification event file descriptor, and the notification event file descriptor is used to notify the first program process that the data transmission of the second program process is completed; the second release step is used to set the data at the target position of all bitmap fields to a second state value, and clean up related resources of the data stream.
[0153] According to one or more embodiments of the present disclosure, before closing the local inter-process communication connection on the first program process side, the write module is also used to: write a first application closing status value to a target location of a second bitmap field of the shared memory through the first program process; the first application closing status value is used to trigger the closing of the local inter-process communication connection of the second program process.
[0154] According to one or more embodiments of the present disclosure, the reading module is also used to: obtain the connection status of the local inter-process communication connection of the first program process after the second program process reaches the stop condition; if the local inter-process communication connection of the first program process is closed, directly close the local inter-process communication connection on the second program process side; if the local inter-process communication connection of the first program process is not closed, trigger the closing of the local inter-process communication connection of the first program process, and set the second program process to a waiting state until the local inter-process communication connection of the first program process is closed, and then close the local inter-process communication connection on the second program process side.
[0155] According to one or more embodiments of the present disclosure, when the reading module triggers the closing of the local inter-process communication connection of the first program process, it is specifically used to: write a first service closing status value to the target position of the second bitmap field of the shared memory through the second program process; when the first program process detects that the target position of the second bitmap field of the shared memory is the first service closing status value, it triggers the stop condition for closing the local inter-process communication connection, and writes the first application closing status value to the target position of the third bitmap field of the shared memory; when the reading module 32 closes the local inter-process communication connection on the second program process side after the local inter-process communication connection of the first program process is closed, it is specifically used to: when the second program process detects that the target position of the third bitmap field of the shared memory is the first application closing status value, or after exceeding a preset time, close the local inter-process communication connection on the second program process side.
[0156] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, comprising: at least one processor and a memory;
[0157] The memory stores computer-executable instructions;
[0158] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the inter-process data transmission method described in the first aspect and various possible designs of the first aspect.
[0159] In a fourth aspect, according to one or more embodiments of the present disclosure, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer execution instructions. When a processor executes the computer execution instructions, the inter-process data transmission method described in the first aspect and various possible designs of the first aspect is implemented.
[0160] In a fifth aspect, according to one or more embodiments of the present disclosure, a computer program product is provided, including a computer program, which, when executed by a processor, implements the inter-process data transmission method described in the first aspect and various possible designs of the first aspect.
[0161] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0162] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0163] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for transmitting data between processes, characterized in that: include: After establishing a local inter-process communication connection between the first program process and the second program process, obtaining a data flow identifier through the first program process; Writing target data to a data buffer area of a shared memory through the first program process, and after the target data is written, writing a first read-write status value to a target position of a first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier; Performing a busy-wait polling detection on the first bitmap field of the shared memory through the second program process, and if the first read-write state value is detected at the target position of the first bitmap field, obtaining the target data output by the first program process from the data buffer area; The obtaining of the data flow identifier through the first program process includes: The first program process sends a handshake request message to the second program process through the local inter-process communication connection, and the handshake request message is used to register a data stream transmission task on the second program process side; the second program process processes the handshake request message, generates a handshake response message, and returns it to the first program process, and the handshake response message includes a data stream identifier corresponding to the data stream transmission task; the first program process receives the handshake response message to obtain the data stream identifier.
2. The inter-process data transmission method according to claim 1, characterized in that: The handshake request message includes a first request field and / or a second request field, wherein the first request field is used to determine the program version information of the second program process adapted by the first program process; and the second request field is used to characterize the memory space required for the data stream transmission task.
3. The inter-process data transmission method according to claim 1, characterized in that: The handshake response message also includes at least one of the following: The first response field is used to indicate the maximum concurrency of the second program process in executing the data stream transmission task; A second response field is used to indicate the memory capacity of the shared memory; The third response field is used to indicate the bitmap field in the shared memory corresponding to the data stream transmission task.
4. The inter-process data transmission method according to claim 1, characterized in that: Writing the target data to the data buffer area of the shared memory through the first program process includes: Get the offset address of the data buffer; The data buffer area is determined according to the offset address, and the target data is written into the data buffer area.
5. The inter-process data transmission method according to claim 4, characterized in that: The method further comprises: Obtaining the data length of the target data; Writing the data length into the data length field before the data buffer area; The step of obtaining target data output by the first program process from the data buffer area includes: Obtaining the target data length corresponding to the data stream identifier from the data length field of the shared memory; Based on the target data length, the data buffer is read to obtain the target data.
6. The inter-process data transmission method according to claim 1, characterized in that: The method further comprises: After the first program process reaches a stop condition, closing a local inter-process communication connection on the first program process side; When the second program process monitors that the first program process closes the local inter-process communication connection, the local inter-process communication connection on the second program process side is closed.
7. The inter-process data transmission method according to claim 6, characterized in that: Closing the local inter-process communication connection on the second program process side includes: Executing a first release step and a second release step in sequence to close the local inter-process communication connection on the second program process side; Wherein, the first release step is used to write a notification event file descriptor and then close the notification event file descriptor, and the notification event file descriptor is used to notify the first program process that the data transmission of the second program process is completed; The second releasing step is used to set the data at the target positions of all bitmap fields to the second state value and clean up the related resources of the data stream.
8. The inter-process data transmission method according to claim 6, characterized in that: Before closing the local inter-process communication connection on the first program process side, the method further includes: A first application closing status value is written to a target location of a second bitmap field of the shared memory through the first program process; the first application closing status value is used to trigger the closing of a local inter-process communication connection of the second program process.
9. The inter-process data transmission method according to claim 1, characterized in that: The method further comprises: After the second program process reaches a stop condition, obtaining a connection state of a local inter-process communication connection of the first program process; If the local inter-process communication connection of the first program process is closed, directly closing the local inter-process communication connection on the second program process side; If the local inter-process communication connection of the first program process is not closed, the closing of the local inter-process communication connection of the first program process is triggered, and the second program process is set to a waiting state for closing until the local inter-process communication connection of the first program process is closed, and then the local inter-process communication connection on the second program process side is closed.
10. The inter-process data transmission method according to claim 9, characterized in that: The triggering of closing the local inter-process communication connection of the first program process includes: Writing a first service shutdown state value to a target location of a second bitmap field of the shared memory through the second program process; When the first program process detects that the target position of the second bitmap field of the shared memory is the first service shutdown state value, triggering a stop condition for closing the local inter-process communication connection, and writing the first application shutdown state value to the target position of the third bitmap field of the shared memory; The method of closing the local inter-process communication connection on the second program process side after the local inter-process communication connection on the first program process is closed includes: When the second program process detects that the target position of the third bitmap field of the shared memory is the first application closing state value, or exceeds a preset time, the local inter-process communication connection on the second program process side is closed.
11. An inter-process data transmission device, characterized in that: include: an acquisition module, configured to obtain a data flow identifier through the first program process after establishing a local inter-process communication connection between the first program process and the second program process; A writing module, used for writing target data to a data buffer area of a shared memory through the first program process, and after the target data is written, writing a first read-write status value to a target position of a first bitmap field of the shared memory based on the data stream identifier, wherein the target position is determined based on the data stream identifier; a reading module, configured to perform a busy-wait polling detection on the first bitmap field of the shared memory through a second program process, and if the first read-write state value is detected at a target position of the first bitmap field, then obtain target data output by the first program process from the data cache area; When the data flow identifier is obtained through the first program process, the acquisition module is specifically used to: The first program process sends a handshake request message to the second program process through the local inter-process communication connection, wherein the handshake request message is used to register a data stream transmission task on the second program process side; Processing the handshake request message through the second program process, generating a handshake response message, and returning the message to the first program process, wherein the handshake response message includes a data stream identifier corresponding to the data stream transmission task; The handshake response message is received through the first program process to obtain the data flow identifier.
12. An electronic device, characterized in that: include: Processor and memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor executes the inter-process data transmission method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions. When the processor executes the computer-executable instructions, the inter-process data transmission method according to any one of claims 1 to 10 is implemented.
14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the inter-process data transmission method according to any one of claims 1 to 10 is implemented.
