A cross-process communication method and system

By creating intermediate files in shared memory space and using filename changes to indicate completion, the complexity of inter-process data transfer is solved, resulting in system simplification and improved maintainability.

CN121255498BActive Publication Date: 2026-02-24SHENZHEN XIYUE ZHIHUI DATA CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511802756.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-03
Publication Date
2026-02-24
Estimated Expiration
2045-12-03

AI Technical Summary

Technical Problem

Existing technologies involve complex inter-process data transmission, strong code coupling, and difficult system maintenance.

Method used

Cross-process communication is achieved by creating intermediate files in a shared memory space, and filename changes are used to indicate when information preparation is complete, thus simplifying the inter-process communication process.

Benefits of technology

It greatly simplifies inter-process data transfer, improves system maintainability and scalability, and reduces program design complexity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121255498B_ABST
    Figure CN121255498B_ABST
Patent Text Reader

Abstract

The application discloses a cross-process communication method and relates to the technical field of application programs, and specifically comprises the following steps: a first process newly creates a file including second process information and information to be transmitted in a shared space; the second process traverses the files in the shared space and extracts the file including the second process information as an intermediate file; after the second process extracts the information from the intermediate file, the intermediate file is deleted; and the first process obtains the state of the intermediate file, thereby completing the transmission of the information. The application greatly simplifies the implementation mode of traditional inter-process data transmission and reply, improves the maintainability, expandability and robustness of a software system, and reduces the complexity of program design.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of application technology, and more specifically to a cross-process communication method and system. Background Technology

[0002] Inter-Process Communication (IPC) refers to the technologies and mechanisms for data transmission and communication between different processes. It is an important component of operating systems, used to enable data sharing, communication, and cooperation between processes. IPC can achieve inter-process communication through pipes, semaphores, shared memory, message queues, and other methods. Through IPC, processes can send messages to each other, share resources, and synchronize operations, thereby enabling more efficient and flexible system designs. IPC has a wide range of applications, including inter-process data transmission, collaborative processing, and concurrency control.

[0003] Typically, sending and receiving data between multiple processes on a single machine uses shared memory, message queues, or internal socket communication. This requires professional programmers to call system APIs and results in strong code coupling between processes, making system maintenance complex and upgrades difficult. Summary of the Invention

[0004] The purpose of this invention is to propose a cross-process communication method to solve one or more technical problems existing in the prior art, and at least provide a beneficial option or create conditions.

[0005] To achieve the above technical objectives, the technical solution of the present invention is as follows:

[0006] In a first aspect, the present invention provides a cross-process communication method, the method comprising the following steps:

[0007] Step 1: The first process creates a new file in the shared space containing information about the second process and the information to be transferred;

[0008] Step 2: The second process traverses the files in the shared space and extracts files including the second process information as intermediate files;

[0009] Step 3: After the second process extracts information from the intermediate file, it deletes the intermediate file.

[0010] Furthermore, in step 1, the sub-step of the first process creating a file in the shared space containing information about the second process and the information to be transferred is as follows:

[0011] Step 1.1: The first process creates an intermediate file in the shared space. The filename of the intermediate file includes the names of the first process and the second process. The intermediate file contains information that the first process needs to pass to the second process.

[0012] Step 2.2: The first process writes information to the intermediate file and adds a file writing completion field to the filename of the intermediate file.

[0013] Preferably, the shared space is a memory file system or directory that the first process and the second process have permission to access and modify.

[0014] Preferably, the shared space is the / dev / shm directory under Linux.

[0015] Preferably, the intermediate file is a file with the .DAT extension.

[0016] Further, in step 1.1, the intermediate file is named A_send_to_B.DAT, where A is the first process, i.e., the process that needs to send the message, and B is the second process, i.e., the destination process for the first process to send the information.

[0017] Further, in step 1.2, the required information is written into A_send_to_B.DAT, and after writing, the file name is changed to A_send_to_B.DAT.FIN.

[0018] Further, in step 2, the sub-step of the second process traversing the files in the shared space and extracting files including the second process information as intermediate files is as follows:

[0019] The second process monitors file changes within the shared space. If it detects a file whose filename contains the second process, it uses that file as an intermediate file and reads its contents.

[0020] Furthermore, the content includes information or instructions that the first process needs to communicate with the second process.

[0021] Furthermore, the second process traverses the / dev / shm directory or monitors the callback function through the / dev / shm directory, and after finding A_send_to_B.DAT.FIN, extracts information from A_send_to_B.DAT.FIN.

[0022] Further, in step 3, the sub-step of deleting the intermediate file after the second process extracts information from the intermediate file is as follows:

[0023] After the second process reads the information of the intermediate file, it modifies the filename of the intermediate file or deletes the intermediate file. After the first process obtains the changes to the intermediate file, it marks the transmission of the information to be transmitted as complete.

[0024] Preferably, after the second process reads the information from the intermediate file, it deletes the A_send_to_B.DAT.FIN file. The first process detects that A_send_to_B.DAT.FIN has been deleted and can then know that the information has been successfully transmitted to the second process.

[0025] Preferably, all undefined variables in this invention, if not explicitly defined, can be manually set thresholds.

[0026] Secondly, the present invention provides a cross-process communication system, the system being used to run a first process and a second thread, the system including a shared space and a file operation module, the shared space being a memory file system or directory that the first process and the second process have permission to access and modify, and the file operation module being used to handle file creation, deletion and renaming operations.

[0027] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the inter-process communication method provided in the first aspect of the present invention.

[0028] Fourthly, the present invention provides an electronic device, comprising: a memory storing a computer program thereon; and a processor for executing the computer program in the memory to implement the steps of the cross-process communication method provided by the present invention.

[0029] Compared with the prior art, the present invention has the following beneficial technical effects:

[0030] It significantly simplifies the traditional implementation of inter-process data sending and replying, improving the maintainability, scalability, and robustness of the software system. It also reduces the complexity of program design. Attached Figure Description

[0031] Figure 1 A flowchart of a cross-process communication method provided by the present invention. Detailed Implementation

[0032] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. The specific embodiments described herein are only for explaining the invention and are not intended to limit the invention.

[0033] It should also be understood that the following embodiments are only used to further illustrate the present invention and should not be construed as limiting the scope of protection of the present invention. Any non-essential improvements and adjustments made by those skilled in the art based on the above description of the present invention are within the scope of protection of the present invention. The specific process parameters, etc., in the following examples are merely examples within a suitable range; that is, those skilled in the art can make appropriate selections within the range based on the description herein, and are not intended to be limited to the specific values ​​in the examples below.

[0034] The following is an exemplary description of a cross-process communication method provided by the present invention.

[0035] like Figure 1 The diagram shown is a flowchart of a cross-process communication method. The following section will combine... Figure 1 This invention describes a cross-process communication method according to an embodiment of the present invention, the method comprising the following steps:

[0036] Step 1: The first process creates a new file in the shared space containing information about the second process and the information to be transferred;

[0037] Step 2: The second process traverses the files in the shared space and extracts files including the second process information as intermediate files;

[0038] Step 3: After the second process extracts information from the intermediate file, it deletes the intermediate file. Example

[0039] The first and second processes monitor / dev / shm (this directory is a memory file system, and the generated files are actually placed in memory) for changes in the directory. When files are added, deleted, or their contents are changed in this directory, the first and second processes can detect them.

[0040] The first and second processes can be shell scripts, using simple logic to search for files under / dev / shm in a loop.

[0041] The first process needs to send "Hello A" data to the second process. First, an empty file A_send_to_B.DAT is generated in the / dev / shm directory.

[0042] Write the message "Hello A" to A_send_to_B.DAT

[0043] Rename A_send_to_B.DAT to A_send_to_B.DAT.FIN, where .FIN indicates that the data is ready.

[0044] When the second process is searching / dev / shm (or in the / dev / shm directory monitoring callback function), it learns that there is an additional file named A_send_to_B.DAT.FIN under / dev / shm. Based on the filename, it knows that the data was sent from the first process to the second process. Therefore, the second process opens the file to receive the data, and then deletes A_send_to_B.DAT.FIN, thus completing the information transfer from the first process to the second process.

[0045] The second process needs to reply to the first process with the message "HI A, I am fine". First, it generates an empty file named B_send_to_A.DAT in the / dev / shm directory.

[0046] Write the message "HI A,I am fine" to B_send_to_A.DAT

[0047] Rename B_send_to_A.DAT to B_send_to_A.DAT.FIN, where .FIN indicates that the data is ready.

[0048] The first process uses the same technique as in step (5) to extract the reply data sent by the second process.

[0049] The technology of this invention is reliable. In Unix-like systems, the rename system call is atomic. It can be understood that the entire process before renaming A_send_to_B.DAT to A_send_to_B.DAT.FIN is a transaction, and the renaming is equivalent to the transaction being committed.

[0050] Preferably, all undefined variables in this invention, if not explicitly defined, can be manually set thresholds.

[0051] The present invention also provides a cross-process communication system, the system being used to run a first process and a second thread, the system including a shared space and a file operation module, the shared space being a memory file system or directory that the first process and the second process have permission to access and modify, and the file operation module being used to handle file creation, deletion and renaming operations.

[0052] The described inter-process communication system can run on computing devices such as desktop computers, laptops, handheld computers, and cloud servers. The system that can run on this inter-process communication system may include, but is not limited to, processors and memory. Those skilled in the art will understand that the examples described are merely illustrations of an inter-process communication system and do not constitute a limitation on such a system. It may include more or fewer components, or combinations of certain components, or different components. For example, the inter-process communication system may also include input / output devices, network access devices, buses, etc.

[0053] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the inter-process communication system, connecting various parts of the system via various interfaces and lines.

[0054] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the cross-process communication system by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory may include random access memory (RAM), and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0055] Although the invention has been described in considerable detail and particularly with regard to several of the described embodiments, it is not intended to limit itself to any of these details or embodiments or any particular embodiment, thereby effectively covering the intended scope of the invention. Furthermore, the invention has been described above with respect to embodiments foreseeable by the inventors in order to provide a useful description, and non-substantial modifications to the invention that have not yet been foreseen may still represent equivalent modifications.

[0056] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0057] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of the invention.

Claims

1. A cross-process communication method, characterized in that, The method includes the following steps: Step 1: The first process creates a new file in the shared space containing information about the second process and the information to be transferred; Step 2: The second process traverses the files in the shared space and extracts files including the second process information as intermediate files; Step 3: After the second process extracts information from the intermediate file, it deletes the intermediate file. In step 1, the sub-step whereby the first process creates a file in the shared space containing information about the second process and the information to be transferred is as follows: Step 1.1: The first process creates an intermediate file in the shared space. The filename of the intermediate file includes the names of the first process and the second process. The intermediate file contains information that the first process needs to pass to the second process. Step 2.2: The first process writes information to the intermediate file and adds a file writing completion field to the filename of the intermediate file; In step 3, the sub-step of deleting the intermediate file after the second process extracts information from the intermediate file is as follows: After the second process reads the information of the intermediate file, it modifies the filename of the intermediate file or deletes the intermediate file. After the first process obtains the changes to the intermediate file, it marks the transmission of the information to be transmitted as complete.

2. The cross-process communication method according to claim 1, characterized in that, In step 1, the shared space is a memory file system or directory that the first process and the second process have permission to access and modify.

3. The cross-process communication method according to claim 1, characterized in that, In step 2, the sub-step of the second process traversing the files in the shared space and extracting files including the second process information as intermediate files is as follows: The second process monitors file changes within the shared space. If it detects a file whose filename contains the second process, it uses the corresponding file as an intermediate file and reads the contents of the intermediate file. The content includes information or instructions that the first process needs to communicate with the second process.

4. A cross-process communication system, characterized in that, The system performs the steps of the cross-process communication method described in any one of claims 1 to 3; The system is used to run a first process and a second thread. The system includes a shared space and a file operation module. The shared space is a memory file system or directory that the first process and the second process have permission to access and modify. The file operation module is used to handle file creation, deletion and renaming operations.

5. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the cross-process communication method described in any one of claims 1 to 3.

6. An electronic device, characterized in that, include: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the cross-process communication method according to any one of claims 1 to 3.

Citation Information

Patent Citations

  • Inter-process communication method and device, electronic equipment and storage medium

    CN119201486A

  • Live object level inter process communication in federated backup environment

    US10496497B1