CN111984430A - Many-to-many process communication method and computer readable storage medium - Google Patents

Many-to-many process communication method and computer readable storage medium Download PDF

Info

Publication number
CN111984430A
CN111984430A CN201910428219.4A CN201910428219A CN111984430A CN 111984430 A CN111984430 A CN 111984430A CN 201910428219 A CN201910428219 A CN 201910428219A CN 111984430 A CN111984430 A CN 111984430A
Authority
CN
China
Prior art keywords
data
shared memory
memory
many
communication
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910428219.4A
Other languages
Chinese (zh)
Inventor
何展然
姚亮
施正
牟韵文
黄睿欣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xiamen Yaxon Networks Co Ltd
Original Assignee
Xiamen Yaxon Networks Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xiamen Yaxon Networks Co Ltd filed Critical Xiamen Yaxon Networks Co Ltd
Priority to CN201910428219.4A priority Critical patent/CN111984430A/en
Publication of CN111984430A publication Critical patent/CN111984430A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Abstract

The invention discloses a many-to-many process communication method and a computer readable storage medium, wherein the method comprises the following steps: creating an index shared memory, and creating a data shared memory corresponding to each process; creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory; when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory; and the second process acquires the communication data from the corresponding data sharing memory. The invention can solve the problems that any two processes among a plurality of processes can not be directly communicated and the control right of the shared memory area can not be released in time.

Description

Many-to-many process communication method and computer readable storage medium
Technical Field
The present invention relates to the field of process communication technologies, and in particular, to a many-to-many process communication method and a computer-readable storage medium.
Background
A process is a basic unit for resource allocation and scheduling of a computer system, and can be regarded as a running program. A multitasking operating system such as Linux can run a plurality of programs simultaneously, and each running program instance constitutes a process. With the increasing software application requirements of different scene platforms, a multi-process program can better meet the user requirements of many specific occasions compared with a single-process application.
Because different processes run in different respective memory spaces, one side cannot sense the modification of the variable and the other side, information transmission among the processes cannot be directly carried out through the variable or other data structures, and only can be completed through communication among the processes. Existing computer technology provides several mechanisms for interprocess communication, such as: pipes, message queues, sockets, etc. For an application scene of communication between processes of the host, the communication mechanism based on the shared memory has the characteristics of large data transmission quantity and high speed.
At present, the interprocess communication mode based on the shared memory has a plurality of designs, and when the communication mode highlights the advantages of the design, at least the following problems exist:
1. only 1-to-1 or 1-to-many inter-process communication is supported, any two processes among a plurality of (more than 2) processes cannot be directly communicated, or a middleware module is required to be relied on, and point-to-point direct connection cannot be realized;
2. when reading and writing, the shared memory area can cause blocking waiting due to some business logic operations with large expenditure, and the control right cannot be released in time.
Disclosure of Invention
The technical problem to be solved by the invention is as follows: a many-to-many process communication method and a computer readable storage medium are provided, which solve the problems that any two processes among a plurality of processes can not directly communicate and the control right of a shared memory region can not be released in time.
In order to solve the technical problems, the invention adopts the technical scheme that: a many-to-many process communication method, comprising:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
and the second process acquires the communication data from the corresponding data sharing memory.
The invention also relates to a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
And the second process acquires the communication data from the corresponding data sharing memory.
The invention has the beneficial effects that: by establishing the data shared memory which is independently used for each process and establishing the mapping relation between the processes and the data shared memory in the index shared memory, the multiple processes can communicate with each other without passing through other middleware modules, and point-to-point communication can be directly carried out between every two processes, so that the operation waiting of the same data shared memory is avoided to a greater extent, and the time efficiency of the communication between the processes is improved. The invention can solve the problems that any two processes among a plurality of processes can not be directly communicated and the control right of the shared memory area can not be released in time.
Drawings
FIG. 1 is a flow chart of a many-to-many process communication method of the present invention;
FIG. 2 is a flowchart of a method according to a first embodiment of the present invention;
fig. 3 is a logic diagram of a first embodiment of the invention.
Detailed Description
In order to explain technical contents, objects and effects of the present invention in detail, the following detailed description is given with reference to the accompanying drawings in conjunction with the embodiments.
The most key concept of the invention is as follows: creating an independent data sharing memory for each process, creating a mapping relation between the process and the data sharing memory in the index sharing memory, and creating a data queue in each process.
Referring to fig. 1, a many-to-many process communication method includes:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
and the second process acquires the communication data from the corresponding data sharing memory.
From the above description, the beneficial effects of the present invention are: the method can avoid the operation waiting of the same data sharing memory to a greater extent, and improve the time efficiency of the inter-process communication.
Further, after the creating the index shared memory and creating the data shared memory corresponding to each process, respectively, the method further includes:
and locking the index shared memory and the data shared memory.
As can be seen from the above description, by performing the locking operation, the security and robustness of the logic can be increased, and the deadlock phenomenon can be avoided.
Further, before the second process obtains the communication data from the corresponding data shared memory, the method further includes:
a data queue is created in each process separately.
Further, after the second process obtains the communication data from the corresponding data shared memory, the method further includes:
the second process copies the communication data to a data queue of the second process;
and the second process acquires the communication data from the data queue of the second process.
It can be known from the above description that the data queue is created in the process, so that the data shared memory is equivalent to a temporary cache center, and the problem of blocking of the shared memory can be avoided.
Further, the mapping relationship is a hash mapping relationship.
As can be seen from the above description, the subsequent search efficiency can be improved.
The invention also proposes a computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps as described above.
Example one
Referring to fig. 2-3, a first embodiment of the present invention is: a many-to-many process communication method can be applied to a multitask operating system, as shown in FIG. 2, and includes the following steps:
s1: creating an index shared memory and locking the index shared memory.
For example, a shared memory M is created as an index mapping region, and lock protection is performed on M, where lock protection refers to performing a locking operation on the shared memory to ensure that only one process can operate on it at the same time. By performing lock protection operation, the security and the robustness of the logic can be increased, and the deadlock phenomenon is avoided.
S2: and respectively establishing a one-to-one corresponding data shared memory for each process, and locking the data shared memories. Preferably, when the process is started, the corresponding data shared memory is created for the process.
For example, assume that there is process A, process B, and process C. When the process A, B, C is started, the corresponding data shared memories MA, MB, and MC are created respectively, and then lock protection operations are performed on MA, MB, and MC.
S3: creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory; further, the unique identifier of the process and the address of the data shared memory corresponding to the process can be mapped in an associated manner.
Preferably, the mapping relationship is a hash mapping relationship, that is, a hash table structure is used to map and store the shared memory addresses of the multiple processes. By adopting the hash table to record the corresponding relation between the index value and the node, the node can be directly searched without sequentially storing the node, and only by presetting a unique index value (supporting integer and character string) for each process, the corresponding process can be directly searched, and the searching efficiency can be improved.
For example, hash association mapping is performed on the process a and the MA in the index shared memory M, and the obtained hash mapping relationship may be represented as process a < > MA; by analogy, the following results are obtained: process B & gt MB and process C & gt MC.
S4: respectively creating a data queue in each process, and locking the data queue.
For example, a lock-protected data queue QA, QB, QC is created in process A, B, C, respectively, dedicated to caching data copied from its corresponding data-sharing memory.
By creating a data queue in a process for caching received messages and data which are not processed in time and enabling a data sharing memory to be a temporary cache center, the situations of blocking and losing under the conditions that the communication between the processes is too fast and certain messages are processed in time can be avoided, and the problem of blocking of the sharing memory can be avoided.
S5: when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes the communication data into the corresponding data shared memory.
S6: and when the second process detects that data is written into the corresponding data sharing memory, the second process acquires the communication data from the corresponding data sharing memory and copies the communication data into the data queue of the second process.
S7: and the second process acquires the communication data from the data queue of the second process and processes the communication data.
For example, as shown in fig. 3, when a process B wants to communicate with a process a, first, a data shared memory MA corresponding to the process a is searched in an index shared memory M (i.e., an index area), and then communication data is written into the data shared memory MA. When process A detects that MA has data written to it, it immediately fetches the data and copies it to QA. The process A performs data fetching operation on QA, and then performs corresponding logic processing.
Similarly, when communication is to be performed to the process B or the process C, the same flow operation is performed.
Wherein, the steps S1, S2 and S4 may not be in sequence.
In this embodiment, one process is dedicated to receive data corresponding to one shared memory of the process, so that when different processes send data to each other, transmission channels between data are different, and process 1 needs to communicate with process 2 without passing through other middleware modules, and direct point-to-point communication can be achieved. That is, when a plurality of processes communicate with each other, the processes can directly communicate one to one without relying on other processes and other data hubs.
In the embodiment, the data sharing memory which is independently used is created for each process, the data cache queue is created in each process, and the mapping relation between the processes and the data sharing memory is created in the index sharing memory, so that the multiple processes can communicate with each other without passing through other middleware modules, and the two processes can directly communicate point to point, thereby avoiding the operation waiting of the same data sharing memory to a great extent and improving the time efficiency of the inter-process communication.
Example two
The present embodiment is a computer-readable storage medium corresponding to the above-mentioned embodiments, on which a computer program is stored, which when executed by a processor implements the steps of:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
And the second process acquires the communication data from the corresponding data sharing memory.
Further, after the creating the index shared memory and creating the data shared memory corresponding to each process, respectively, the method further includes:
and locking the index shared memory and the data shared memory.
Further, before the second process obtains the communication data from the corresponding data shared memory, the method further includes:
a data queue is created in each process separately.
Further, after the second process obtains the communication data from the corresponding data shared memory, the method further includes:
the second process copies the communication data to a data queue of the second process;
and the second process acquires the communication data from the data queue of the second process.
Further, the mapping relationship is a hash mapping relationship.
In summary, according to the many-to-many process communication method and the computer-readable storage medium provided by the present invention, the data shared memory used independently is created for each process, the data cache queue is created in each process, and the mapping relationship between the process and the data shared memory is created in the index shared memory, so that the multiple processes can communicate with each other without passing through other middleware modules, and the two processes can directly perform point-to-point communication, thereby avoiding the operation wait on the same data shared memory to a greater extent, and improving the time efficiency of the inter-process communication. The invention can solve the problems that any two processes among a plurality of processes can not be directly communicated and the control right of the shared memory area can not be released in time.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all equivalent changes made by using the contents of the present specification and the drawings, or applied directly or indirectly to the related technical fields, are included in the scope of the present invention.

Claims (10)

1. A many-to-many process communication method, comprising:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
when the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
and the second process acquires the communication data from the corresponding data sharing memory.
2. The many-to-many process communication method according to claim 1, wherein after the creating the index shared memory and creating the one-to-one data shared memory for each process respectively, further comprising:
And locking the index shared memory and the data shared memory.
3. The many-to-many process communication method according to claim 1, wherein before the second process obtains the communication data from its corresponding data-sharing memory, further comprising:
a data queue is created in each process separately.
4. The many-to-many process communication method according to claim 3, wherein after the second process obtains the communication data from the corresponding data-sharing memory, the method further comprises:
the second process copies the communication data to a data queue of the second process;
and the second process acquires the communication data from the data queue of the second process.
5. A many-to-many process communication method according to claim 1, wherein the mapping relationship is a hash mapping relationship.
6. A computer-readable storage medium, on which a computer program is stored, which program, when executed by a processor, performs the steps of:
creating an index shared memory, and creating a data shared memory corresponding to each process;
creating a mapping relation between a process and a corresponding data sharing memory, and storing the mapping relation to the index sharing memory;
When the first process needs to communicate with the second process, the first process searches the data shared memory corresponding to the second process in the index shared memory and writes communication data into the corresponding data shared memory;
and the second process acquires the communication data from the corresponding data sharing memory.
7. The computer-readable storage medium of claim 6, wherein after creating the index shared memory and creating a one-to-one data shared memory for each process, the method further comprises:
and locking the index shared memory and the data shared memory.
8. The computer-readable storage medium of claim 6, wherein before the second process obtains the communication data from its corresponding data-sharing memory, further comprising:
a data queue is created in each process separately.
9. The computer-readable storage medium of claim 8, wherein after the second process obtains the communication data from its corresponding data-sharing memory, further comprising:
the second process copies the communication data to a data queue of the second process;
And the second process acquires the communication data from the data queue of the second process.
10. The computer-readable storage medium of claim 6, wherein the mapping is a hash mapping.
CN201910428219.4A 2019-05-22 2019-05-22 Many-to-many process communication method and computer readable storage medium Pending CN111984430A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910428219.4A CN111984430A (en) 2019-05-22 2019-05-22 Many-to-many process communication method and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910428219.4A CN111984430A (en) 2019-05-22 2019-05-22 Many-to-many process communication method and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN111984430A true CN111984430A (en) 2020-11-24

Family

ID=73436508

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910428219.4A Pending CN111984430A (en) 2019-05-22 2019-05-22 Many-to-many process communication method and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN111984430A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113407414A (en) * 2021-06-24 2021-09-17 厦门科灿信息技术有限公司 Program operation monitoring method, device, terminal and storage medium
CN113760578A (en) * 2021-08-28 2021-12-07 特斯联科技集团有限公司 Method, device, equipment and computer program for cross-process rapid transmission of big data

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113407414A (en) * 2021-06-24 2021-09-17 厦门科灿信息技术有限公司 Program operation monitoring method, device, terminal and storage medium
CN113760578A (en) * 2021-08-28 2021-12-07 特斯联科技集团有限公司 Method, device, equipment and computer program for cross-process rapid transmission of big data
CN113760578B (en) * 2021-08-28 2022-04-19 特斯联科技集团有限公司 Method, device, equipment and computer program for cross-process rapid transmission of big data

Similar Documents

Publication Publication Date Title
US11500689B2 (en) Communication method and apparatus
TWI549060B (en) Access methods and devices for virtual machine data
US8381230B2 (en) Message passing with queues and channels
US10564997B2 (en) Computing system for securely executing a secure application in a rich execution environment
CN110795206B (en) System and method for facilitating cluster-level caching and memory space
US9977609B2 (en) Efficient accesses of data structures using processing near memory
US10733101B2 (en) Processing node, computer system, and transaction conflict detection method
WO2021244155A1 (en) Inter-process communication method and inter-process communication apparatus
US11269772B2 (en) Persistent memory storage engine device based on log structure and control method thereof
US20130290667A1 (en) Systems and methods for s-list partitioning
US11656779B2 (en) Computing system and method for sharing device memories of different computing devices
WO2024041576A1 (en) Live migration method and system for virtual machine, and device and storage medium
WO2024036985A1 (en) Storage system, computational storage processor and solid-state drive thereof, and data reading method and data writing method therefor
CN111984430A (en) Many-to-many process communication method and computer readable storage medium
CN112256457A (en) Data loading acceleration method and device based on shared memory, electronic equipment and storage medium
CN115470156A (en) RDMA-based memory use method, system, electronic device and storage medium
US8543722B2 (en) Message passing with queues and channels
US10082978B2 (en) Distributed shared log storage system having an adapter for heterogenous big data workloads
CN115080277A (en) Inter-core communication system of multi-core system
CN117311817A (en) Coprocessor control method, device, equipment and storage medium
US20200319939A1 (en) Distributed system for distributed lock management and method for operating the same
US10073809B2 (en) Technologies for scalable remotely accessible memory segments
CN113138859A (en) General data storage method based on shared memory pool
US10956240B2 (en) Sharing data by a virtual machine
CN105183668A (en) Cache refreshing method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination