CN110069346B - Method and device for sharing resources among multiple processes and electronic equipment - Google Patents

Method and device for sharing resources among multiple processes and electronic equipment Download PDF

Info

Publication number
CN110069346B
CN110069346B CN201910342769.4A CN201910342769A CN110069346B CN 110069346 B CN110069346 B CN 110069346B CN 201910342769 A CN201910342769 A CN 201910342769A CN 110069346 B CN110069346 B CN 110069346B
Authority
CN
China
Prior art keywords
resource
shared
target
shared resource
request
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.)
Active
Application number
CN201910342769.4A
Other languages
Chinese (zh)
Other versions
CN110069346A (en
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.)
Hangzhou DPTech Technologies Co Ltd
Original Assignee
Hangzhou DPTech Technologies 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 Hangzhou DPTech Technologies Co Ltd filed Critical Hangzhou DPTech Technologies Co Ltd
Priority to CN201910342769.4A priority Critical patent/CN110069346B/en
Publication of CN110069346A publication Critical patent/CN110069346A/en
Application granted granted Critical
Publication of CN110069346B publication Critical patent/CN110069346B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Abstract

The application provides a method and a device for sharing resources among multiple processes, electronic equipment and a machine-readable storage medium. In the application, a request for creating a shared resource by the first process is received, and the shared resource is stored; and allocating a resource identifier uniquely corresponding to the shared resource; receiving an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource; in response to the acquisition request, searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if the resource identifier exists, the shared resource corresponding to the resource identifier matched with the target resource identifier is copied, so that the second process obtains the corresponding copied resource, and the resource sharing among a plurality of processes running locally is realized.

Description

Method and device for sharing resources among multiple processes and electronic equipment
Technical Field
The present application relates to the field of operating system technologies, and in particular, to a method and an apparatus for sharing resources among multiple processes, an electronic device, and a machine-readable storage medium.
Background
A process is a running activity of a program in an operating system on a certain data set, and is a basic unit for resource allocation and scheduling of the operating system. A program is a static description of instructions, data, and their organization corresponding to a process, which is a dynamic execution entity corresponding to the program.
IPC (inter process communication) is a communication mechanism provided by an operating system. Program developers write development programs based on IPC, and can coordinate different processes running in an operating system and mutually transmit or exchange information.
Disclosure of Invention
The application provides a resource sharing method among multiple processes, which is applied to a kernel of an operating system, wherein the operating system further comprises a first process for issuing shared resources and a second process for acquiring the shared resources, the first process and the second process communicate based on the kernel, and the method comprises the following steps:
receiving a request for establishing a shared resource by the first process, and storing the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource;
receiving an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource;
in response to the acquisition request, searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
Optionally, before the receiving the request for acquiring the target shared resource by the second process, the method further includes:
receiving a grouping request of the second process, wherein the grouping request corresponds to the target resource identifier;
searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if so, allowing the second process to join the process group.
Optionally, when there is a change in the shared resource, the method further includes:
receiving a change request of the first process for the shared resource, and updating the shared resource and the corresponding copied resource based on the change request;
and sending a change notification of the shared resource to the corresponding process group based on the resource identifier uniquely corresponding to the shared resource, so that the processes in the process group corresponding to the shared resource acquire the updated copied resource.
Optionally, when receiving a group departure request of the second process grouped with the process corresponding to the target resource identifier, the method further includes:
deleting the second process from the process group;
and deleting the copied resource corresponding to the second process.
The present application further provides a device for sharing resources among multiple processes, where the device is applied to a kernel of an operating system, the operating system further includes a first process for issuing shared resources and a second process for acquiring shared resources, where the first process and the second process communicate with each other based on the kernel, and the device includes:
the creation module receives a creation request of the first process to the shared resource and stores the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource;
the acquisition module receives an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource;
the sharing module is used for responding to the acquisition request and searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
Optionally, before the receiving of the request for acquiring the target shared resource by the second process, the acquiring module further:
receiving a grouping request of the second process, wherein the grouping request corresponds to the target resource identifier;
searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if so, allowing the second process to join the process group.
Optionally, when there is a change in the shared resource, the creating module further:
receiving a change request of the first process for the shared resource, and updating the shared resource and the corresponding copied resource based on the change request;
and sending a change notification of the shared resource to the corresponding process group based on the resource identifier uniquely corresponding to the shared resource, so that the processes in the process group corresponding to the shared resource acquire the updated copied resource.
Optionally, when receiving a group departure request of the second process grouped with the process corresponding to the target resource identifier, the sharing module further:
deleting the second process from the process group;
and deleting the copied resource corresponding to the second process.
The application also provides an electronic device, which comprises a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are mutually connected through the bus;
the memory stores machine-readable instructions, and the processor executes the method by calling the machine-readable instructions.
The present application also provides a machine-readable storage medium having stored thereon machine-readable instructions which, when invoked and executed by a processor, implement the above-described method.
Through the above embodiment, the shared resources of the maintained process and the corresponding resource identifiers thereof are created based on the kernel; and acquiring the copy resource corresponding to the resource identifier matched with the target resource by managing and maintaining other processes based on the target resource identifier, thereby realizing the resource sharing among a plurality of processes running locally.
Drawings
FIG. 1 is a flowchart of a method for resource sharing among multiple processes provided by an exemplary embodiment;
FIG. 2 is an interaction diagram of a multi-process communication process provided by an exemplary embodiment;
FIG. 3 is a block diagram of an apparatus for sharing resources among multiple processes in accordance with an illustrative embodiment;
fig. 4 is a hardware block diagram of an electronic device according to an exemplary embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
In order to make those skilled in the art better understand the technical solution in the embodiment of the present application, a brief description will be given below to the related technology of resource sharing among multiple processes related to the embodiment of the present application.
As programs are developed more and more complex, the resources of one process often need to be shared by other processes due to business and programming requirements. In the prior art, resource sharing among processes is mainly realized through an IPC mechanism based on a shared memory or a third-party process;
the shared memory based IPC mechanism mainly has the following disadvantages: when a program is designed, a programmer needs to be skilled in using a synchronous locking mechanism to prevent a plurality of processes from reading and writing at the same time to cause abnormal shared resources, but once a lock occupying the shared resources for a long time by a certain process is not released, other processes cannot acquire the resource lock, and therefore the shared resources cannot be acquired;
when the third-party process is used as an intermediate medium for communication among a plurality of processes, resource sharing among the processes is realized, the following defects mainly exist: the third-party process needs to maintain high stability and performance, and if the performance of the third-party process is bottleneck or poor in stability, communication among multiple processes is abnormal, so that shared resources cannot be acquired.
The application aims to provide a technical scheme for carrying out multi-process communication based on a resource identifier uniquely corresponding to a process-based shared resource, so as to realize resource sharing.
When the method is realized, an operating system kernel receives a request for establishing the shared resource by the first process and stores the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource; receiving an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource; in response to the acquisition request, searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
In the above scheme, a shared resource of a maintained process and a corresponding resource identifier thereof are created based on a kernel; and acquiring the copy resource corresponding to the resource identifier matched with the target resource by managing and maintaining other processes based on the target resource identifier, thereby realizing the resource sharing among a plurality of processes running locally.
The present application is described below with reference to specific embodiments and specific application scenarios.
Referring to fig. 1, fig. 1 is a flowchart of a resource sharing method among multiple processes according to an embodiment of the present application, where the method is applied to a kernel of an operating system, the operating system further includes a first process that issues a shared resource and a second process that obtains the shared resource, where the first process and the second process communicate with each other based on the kernel, and the method performs the following steps:
102, receiving a request for establishing shared resources by the first process, and storing the shared resources; and allocating a resource identifier uniquely corresponding to the shared resource.
Step 104, receiving an acquisition request of the second process to the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource.
Step 106, responding to the acquisition request, and searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
In this specification, the shared resource may include one or more data of a process in any form that can be shared. For example: the shared resource may be a data structure of the first process, and the data structure includes, but is not limited to, variables, arrays, queues, linked lists, port states, routing states, and the like when the first process is implemented. Another example is: the shared resource may be a segment of a video stream or a message stream. In the present application, the shared resource is not particularly limited. In this specification, the first process refers to a process in the operating system that provides the shared resource to another process, that is, the first process may issue its own shared resource to another process.
In this specification, the second process refers to one or more processes in the operating system that need to acquire the shared resource that has been issued by the first process, that is, the first process needs to acquire the shared resource that has been issued by the first process.
In this specification, the kernel refers to a kernel program in an operating system, and when the kernel runs, a corresponding process is a kernel process. Based on the kernel, the operating system may provide inter-process communication for the first process and the second process, so as to complete sharing of the shared resource among multiple processes, and for convenience of description, the subsequent "kernel process" is simply referred to as "kernel".
Referring to fig. 2, fig. 2 is an interaction diagram of a multi-process communication process according to an embodiment. As shown in fig. 2, the components that communicate include: the system comprises a kernel, a first process and a second process; the first process and the second process communicate based on a kernel; as shown in fig. 2, a first process may publish a shared resource for a second process to obtain the shared resource based on the kernel.
Based on fig. 2, the following technical solutions related to the present application are described in detail by specific embodiments and in combination with "shared resource creation", "shared resource acquisition and cancellation", and "shared resource update":
1) shared resource creation
For ease of understanding, the following detailed techniques involved in the communication between the first process and the second process based on the kernel are introduced.
When the first process and the second process communicate based on the kernel, the first process and the second process communicate based on Socket; the Socket is a common mechanism in IPC communication.
For example: the client process corresponding to the client program developed based on Socket can perform communication and data interaction with the server process corresponding to the server program developed based on Socket by calling a Socket API interface provided by an operating system and through a communication protocol stack provided by the operating system.
It should be noted that, in general, the Socket mechanism is generally applied to multiple inter-process communication of multiple devices under a C/S (client/server) or B/S (browser/server) architecture networking.
In this specification, the first process and the second process communicate based on a Socket provided by the kernel; the first process and the first process are both located in the same device, that is, the first process and the second process are local multiprocesses.
In this specification, the kernel receives a request for creating a shared resource from the first process, and stores the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource.
During implementation, the kernel provides a Socket creation API interface for the first process, and the first process transmits the shared resource to the Socket creation API interface by using the shared resource as an entry, so as to initiate a request for creating the shared resource to the kernel; the kernel responds to the Socket to create API interface call, acquires the shared resource and stores the shared resource in the allocated kernel space; meanwhile, the kernel establishes a return value of an API interface for the Socket and allocates a unique resource identifier in the kernel; wherein, the resource identification is corresponding to the shared resource only. Therefore, the first process obtains the return value of the Socket creation API interface through the Socket creation API interface, that is, the first process obtains the resource identifier uniquely corresponding to the shared resource and allocated by the kernel.
It should be noted that, in another implementation shown, the first process may directly initiate a request for creating the shared resource on the kernel. For example: referring to steps P1 and P2 shown in fig. 2, a first process initiates a request to the kernel to create a shared resource; the kernel receives the creation request, stores the shared resource and distributes a unique resource identifier for the shared resource; and the first process acquires the resource identifier corresponding to the shared resource distributed by the kernel.
When implemented, the resource identifier may be a character string of any Length in TLV (Type, Length, Value) format.
It should be noted that, in this specification, the first process may initiate a request for creating a plurality of shared resources to the kernel, and obtain a corresponding resource identifier allocated by the kernel.
For example, please refer to table 1 for a plurality of shared resources and corresponding resource identifiers stored in the kernel:
resource identification Sharing assetsSource
RES1 SHARE1
RES2 SHARE2
RES3 SHARE3
TABLE 1
It should be noted that, in this specification, when the kernel allocates the corresponding resource identifier for the shared resource, it is required to search whether there is a repeated shared resource in the multiple shared resources and the corresponding resource identifiers stored in the kernel; if not, the shared resource is saved and the corresponding resource identifier is allocated; if the shared resource exists, the allocated corresponding resource identifier corresponding to the shared resource is directly returned.
For example: when the kernel receives a request for creating a SHARE2 from the first process, checks a plurality of shared resources and corresponding resource identifiers stored in the kernel as shown in table 1, and finds that a SHARE2 already exists, the kernel returns an allocated corresponding resource identifier RES2 corresponding to the SHARE2 to the first process.
In this specification, the kernel establishes a corresponding process group for each of the resource identifiers, where the process group may include one or more processes that are to acquire a shared resource corresponding to the resource identifier. For example: the resource identifiers RES1, RES2, RES3 correspond to processes grouped as Process1, Process2, Process3, respectively.
2) Shared resource acquisition, cancellation
In this specification, the target resource refers to one or more shared resources that are issued by the first process and that are already stored in the kernel; the target resource identifier is a resource identifier corresponding to the shared resource issued by the first process and stored in the kernel.
For example, as shown in table 1, when the first process has issued shared resources SHARE1, SHARE2, and SHARE3 to the kernel, and the second process needs to acquire the issued shared resource SHARE3 of the first process, the SHARE3 is the target resource, and RES3 is the target resource identifier.
In an embodiment shown in the above, the second process sends, to the kernel, a group addition request grouped by the process corresponding to the target resource identifier.
During implementation, the kernel provides a Socket connection API interface for the second process, and the first process transmits the target resource identifier as an entry parameter to the Socket connection API interface, so as to initiate a group adding request for grouping the processes to the kernel;
for example, the second Process may group the Process corresponding to the RES3 as the kernel target resource as a Process 3.
In an illustrated embodiment, the kernel receives a group adding request of the second process, where the group adding request is grouped with a process corresponding to the target resource identifier, where the group adding request at least includes the target resource identifier; searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, allowing the second process to join the process group.
In the implementation process, the kernel responds to the Socket connection API interface call, and searches a resource identifier matched with the target resource identifier in the resource identifiers stored by the kernel; and if so, allowing the second process to join the process group.
For example: referring to the step G1 and the step G2 shown in fig. 2, the second process initiates a group adding request for sharing resources to the kernel, wherein a target resource of the group adding request is identified as RES 3; the kernel receives the group adding request, and searches a resource identifier matched with RES3 in the resource identifiers stored by the kernel as shown in Table 1; if the found person RES3 already exists, the kernel adds the second Process to the Process grouping Process3 corresponding to RES 3.
It should be noted that, if the target resource identifier does not exist in the kernel, the kernel rejects the group adding request of the second process, and returns a group adding failure return value to the second process through the Socket connection API interface call.
In an embodiment shown, after the second process successfully joins the process group, the second process initiates an acquisition request for the target shared resource to the kernel; wherein, the obtaining request at least comprises the target resource identifier.
During implementation, the kernel provides a Socket acquisition API interface for the second process, and the first process transmits the target resource identifier as an entry parameter to the Socket acquisition API interface, so as to initiate an acquisition request for the target shared resource to the kernel;
in this specification, the kernel receives an acquisition request of the second process for the target shared resource; wherein, the obtaining request at least comprises a target resource identifier which uniquely identifies the target shared resource;
the kernel responds to the acquisition request, and searches a resource identifier matched with the target resource identifier in the resource identifiers stored by the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
In the implementation process, the kernel responds to the Socket to obtain API interface call, and searches a resource identifier matched with the target resource identifier in the resource identifiers stored by the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
For example, referring to step G3 and step G4 shown in fig. 2, the kernel receives the second process, and obtains a request for SHARE3 as the target shared resource shown in table 1; wherein, the acquisition request at least includes the resource identifier RES3 corresponding to SHARE3, that is, RES3 is a target resource identifier corresponding to a target shared resource SHARE 3; the kernel searches RES3 in the resource identifier stored by the kernel, if RES3 exists, the shared resource SHARE3 corresponding to RES is copied, namely SHARE3 is copied; wherein, the copy resource corresponding to SHARE3, that is, the copy resource; and will notify SHARE3 that the corresponding Process is grouped into a Process in Process 3.
It should be noted that the number of copies of the shared resource may be one or more, and the number of copies is the same as the number of processes in the process group corresponding to the target resource identifier. For example: there may be 10 processes (the second Process) in the Process group Process3 corresponding to the resource identifier RES 3; the kernel needs to copy the SHARE3 by 10 SHAREs, and respectively store the 10 SHAREs of copied resources in the acquisition queue corresponding to the 10 processes; thus, the second process (10 processes) can acquire the copy resource from the corresponding acquisition queue.
In this specification, the shared resource creation is completed in the first process; and the second process takes the resource identifier corresponding to the shared resource as the target resource identifier, and adds the target resource identifier to the process group corresponding to the resource identifier corresponding to the shared resource matched with the target resource identifier;
in an embodiment shown in the above, when the kernel receives a group leaving request of a process group corresponding to the target resource identifier of the second process, the kernel deletes the second process from the process group; and deleting the copied resource corresponding to the second process.
Continuing with the example above, referring to step L1 and step L2 shown in fig. 2, when the kernel receives the request for leaving the Process group Process3 corresponding to RES3 of the second Process, the kernel deletes the second Process from the Process group Process 3; the replicated resource corresponding to Process3 is deleted.
3) Shared resource update
In this specification, the shared resource creation is completed in the first process; and the second process takes the resource identifier corresponding to the shared resource as the target resource identifier, and adds the target resource identifier to the process group corresponding to the resource identifier corresponding to the shared resource matched with the target resource identifier;
in an embodiment shown in the above, when there is a change in the shared resource, the kernel receives a change request for the shared resource from the first process, where the change request at least includes a resource identifier uniquely corresponding to the shared resource; and updating the shared resource based on the change request.
In implementation, the kernel receives the call of the first process to the Socket update API interface, and updates the shared resource and the corresponding copy resource based on the resource identifier uniquely corresponding to the shared resource.
For example, referring to step C1 and step C2 shown in fig. 2, the kernel receives the second process, and the update request for the target shared resource, SHARE2, shown in table 1; wherein, the acquisition request at least comprises resource identification RES2 corresponding to SHARE2 and NewSHARE2 corresponding to SHARE 2; the kernel finds the SHARE2 shown in table 1 based on RES2, and updates the SHARE2 to the new SHARE 2; and updates the copy resource corresponding to the SHARE2 to be the new copy resource corresponding to the new SHARE 2.
Wherein; as shown in table 1, after updating SHARE2, the shared resources and the corresponding resource identifiers stored in the kernel are shown in table 2:
resource identification Sharing resources
RES1 SHARE1
RES2 NewSHARE2
RES3 SHARE3
TABLE 2
In one embodiment, the kernel further sends a notification of change of the shared resource to a corresponding process group based on a resource identifier uniquely corresponding to the shared resource, so that a process in the process group corresponding to the shared resource acquires an updated copy resource.
Continuing with the example above, the kernel sends a notification of changing the shared resource corresponding to RES2 to the Process group Process2 corresponding to RES2, so that the Process in the Process group Process2 corresponding to RES2 obtains the new copied resource corresponding to NewSHARE 2.
In the technical scheme, the shared resources of the maintained process and the corresponding resource identifiers are created based on the kernel; and acquiring the copy resource corresponding to the resource identifier matched with the target resource by managing and maintaining other processes based on the target resource identifier, thereby realizing the resource sharing among a plurality of processes running locally. Due to the fact that the technical scheme is achieved based on the kernel, the stability and the efficiency of communication when resource sharing is conducted among the processes can be greatly improved.
Fig. 3 is a block diagram of a device for sharing resources among multiple processes according to an exemplary embodiment of the present application. Corresponding to the above method embodiment, the present application further provides an embodiment of an inter-process resource sharing device, where the device is applied to a kernel of an operating system, and the operating system further includes a first process that issues a shared resource and a second process that obtains the shared resource, where the first process and the second process communicate with each other based on the kernel, please refer to an exemplary inter-process resource sharing device 30 illustrated in fig. 3, and the device includes:
a creating module 301, configured to receive a request for creating a shared resource from the first process, and store the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource;
an obtaining module 302, configured to receive an obtaining request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource;
the sharing module 303, in response to the obtaining request, searches a resource identifier matched with the target resource identifier from the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
In this embodiment, before the receiving the request for acquiring the target shared resource from the second process, the acquiring module 302 further:
receiving a grouping request of the second process, wherein the grouping request corresponds to the target resource identifier;
searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if so, allowing the second process to join the process group.
In this embodiment, when there is a change in the shared resource, the creating module 301 further:
receiving a change request of the first process for the shared resource, and updating the shared resource and the corresponding copied resource based on the change request;
and sending a change notification of the shared resource to the corresponding process group based on the resource identifier uniquely corresponding to the shared resource, so that the processes in the process group corresponding to the shared resource acquire the updated copied resource.
In this embodiment, when receiving a group departure request of the second process grouped with the process corresponding to the target resource identifier, the sharing module 303 further:
deleting the second process from the process group;
and deleting the copied resource corresponding to the second process.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, wherein the modules described as separate parts may or may not be physically separate, and the parts displayed as modules may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
The systems, devices, modules or modules illustrated in the above embodiments may be implemented by a computer chip or an entity, or by an article of manufacture with certain functionality. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
The embodiment of the multi-process resource sharing apparatus of the present application can be applied to the electronic device shown in fig. 4. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. Taking a software implementation as an example, as a logical device, the device is a machine executable instruction formed by reading a corresponding computer program instruction in a machine readable storage medium through a processor of the electronic device where the device is located and then running the computer program instruction. From a hardware aspect, as shown in fig. 4, the present application is a hardware structure diagram of an electronic device in which a multi-process resource sharing apparatus is located, where, in addition to the processor, the communication interface, the bus, and the machine-readable storage medium shown in fig. 4, the electronic device in which the apparatus is located in the embodiment may also include other hardware according to an actual function of the electronic device, which is not described again.
Correspondingly, an embodiment of the present application further provides a hardware structure of an electronic device of the apparatus shown in fig. 3, please refer to fig. 4, and fig. 4 is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. The apparatus comprises: a communication interface 401, a processor 402, a machine-readable storage medium 403, and a bus 404; the communication interface 401, the processor 402 and the machine-readable storage medium 403 are configured to communicate with each other via a bus 404. The communication interface 401 is used for performing network communication. The processor 402 may be a Central Processing Unit (CPU), and the processor 402 may execute machine-readable instructions stored in a machine-readable storage medium 403 to implement the methods described above.
The machine-readable storage medium 403 referred to herein may be any electronic, magnetic, optical, or other physical storage device that can contain or store information such as executable instructions, data, and the like. For example, the machine-readable storage medium may be: volatile memory, non-volatile memory, or similar storage media. In particular, the machine-readable storage medium 403 may be a RAM (random Access Memory), a flash Memory, a storage drive (e.g., a hard disk drive), a solid state disk, any type of storage disk (e.g., a compact disk, a DVD, etc.), or similar storage medium, or a combination thereof.
Up to this point, the description of the hardware configuration shown in fig. 4 is completed.
Further, the present application provides a machine-readable storage medium, such as machine-readable storage medium 403 in fig. 4, including machine-executable instructions, which can be executed by processor 402 in the data processing apparatus to implement the data processing method described above.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.

Claims (10)

1. A method for sharing resources among multiple processes is applied to a kernel of an operating system, the operating system further comprises a first process for issuing shared resources and a second process for acquiring shared resources, wherein the first process and the second process communicate based on the kernel, and the method comprises the following steps:
receiving a request for establishing a shared resource by the first process, and storing the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource;
receiving an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource;
in response to the acquisition request, searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
2. The method of claim 1, prior to said receiving a request for acquisition of a target shared resource by the second process, further comprising:
receiving a grouping request of the second process, wherein the grouping request corresponds to the target resource identifier;
searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if so, allowing the second process to join the process group.
3. The method of claim 2, wherein when there is a change in the shared resource, further comprising:
receiving a change request of the first process for the shared resource, and updating the shared resource and the corresponding copied resource based on the change request;
and sending a change notification of the shared resource to the corresponding process group based on the resource identifier uniquely corresponding to the shared resource, so that the processes in the process group corresponding to the shared resource acquire the updated copied resource.
4. The method of claim 2, wherein when receiving a request for a departure from a group of processes of the second process grouped corresponding to the target resource identification, further comprising:
deleting the second process from the process group;
and deleting the copied resource corresponding to the second process.
5. An apparatus for sharing resources among multiple processes, the apparatus being applied to a kernel of an operating system, the operating system further including a first process for issuing shared resources and a second process for acquiring shared resources, wherein the first process and the second process communicate based on the kernel, the apparatus comprising:
the creation module receives a creation request of the first process to the shared resource and stores the shared resource; and allocating a resource identifier uniquely corresponding to the shared resource;
the acquisition module receives an acquisition request of the second process for the target shared resource; wherein the acquisition request at least comprises a target resource identifier uniquely identifying the target shared resource;
the sharing module is used for responding to the acquisition request and searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; and if so, copying the shared resource corresponding to the resource identifier matched with the target resource identifier so as to enable the second process to acquire the corresponding copied resource.
6. The apparatus of claim 5, wherein prior to the receiving the request for acquisition of the target shared resource by the second process, the acquisition module is further to:
receiving a grouping request of the second process, wherein the grouping request corresponds to the target resource identifier;
searching a resource identifier matched with the target resource identifier in the resource identifiers stored in the kernel; if so, allowing the second process to join the process group.
7. The apparatus of claim 6, wherein when there is a change in the shared resource, the creation module is further to:
receiving a change request of the first process for the shared resource, and updating the shared resource and the corresponding copied resource based on the change request;
and sending a change notification of the shared resource to the corresponding process group based on the resource identifier uniquely corresponding to the shared resource, so that the processes in the process group corresponding to the shared resource acquire the updated copied resource.
8. The apparatus of claim 6, wherein the sharing module, upon receiving a request for a group departure from the second process for the process group corresponding to the target resource identification, is further to:
deleting the second process from the process group;
and deleting the copied resource corresponding to the second process.
9. An electronic device is characterized by comprising a communication interface, a processor, a memory and a bus, wherein the communication interface, the processor and the memory are connected with each other through the bus;
the memory has stored therein machine-readable instructions, the processor executing the method of any of claims 1 to 4 by calling the machine-readable instructions.
10. A machine-readable storage medium having stored thereon machine-readable instructions which, when invoked and executed by a processor, carry out the method of any of claims 1 to 4.
CN201910342769.4A 2019-04-26 2019-04-26 Method and device for sharing resources among multiple processes and electronic equipment Active CN110069346B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910342769.4A CN110069346B (en) 2019-04-26 2019-04-26 Method and device for sharing resources among multiple processes and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910342769.4A CN110069346B (en) 2019-04-26 2019-04-26 Method and device for sharing resources among multiple processes and electronic equipment

Publications (2)

Publication Number Publication Date
CN110069346A CN110069346A (en) 2019-07-30
CN110069346B true CN110069346B (en) 2021-07-23

Family

ID=67369104

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910342769.4A Active CN110069346B (en) 2019-04-26 2019-04-26 Method and device for sharing resources among multiple processes and electronic equipment

Country Status (1)

Country Link
CN (1) CN110069346B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111190748B (en) * 2019-12-23 2023-06-09 腾讯科技(深圳)有限公司 Data sharing method, device, equipment and storage medium
CN113626134B (en) * 2021-06-29 2024-02-13 广东浪潮智慧计算技术有限公司 Resource replication method, device, equipment and computer readable storage medium
CN113779545A (en) * 2021-08-27 2021-12-10 深圳市优必选科技股份有限公司 Data cross-process sharing method, terminal equipment and computer readable storage medium
CN114064323A (en) * 2021-11-24 2022-02-18 中兴通讯股份有限公司 Resource sharing method, terminal, and computer-readable medium
CN115220911A (en) * 2022-06-17 2022-10-21 中科驭数(北京)科技有限公司 Resource management method, device, equipment and medium
CN117077115B (en) * 2023-10-13 2023-12-15 沐曦集成电路(上海)有限公司 Cross-language multi-process interaction method, electronic equipment and medium in chip verification stage

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102122255A (en) * 2011-03-15 2011-07-13 合肥华云通信技术有限公司 Method for realizing inter-process communication in Linux system by utilizing virtual character equipment and genetlink
CN104714792A (en) * 2013-12-17 2015-06-17 腾讯科技(深圳)有限公司 Multi-process shared data processing method and device
CN105487933A (en) * 2015-11-24 2016-04-13 无锡江南计算技术研究所 Inter-kernel asynchronous message queue and shared memory based inter-domain communication method
CN105978997A (en) * 2016-06-24 2016-09-28 北京百度网讯科技有限公司 Data transmission method and system
CN105991755A (en) * 2015-05-21 2016-10-05 杭州迪普科技有限公司 Service message distribution method and service message distribution device
CN106648939A (en) * 2016-12-30 2017-05-10 上海寰视网络科技有限公司 Method and equipment for inter-process resource sharing

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8726287B2 (en) * 2010-11-24 2014-05-13 Thomson Licensing Method for reducing inter-process communication latency
CN106874125B (en) * 2017-01-13 2021-04-06 北京元心科技有限公司 Method and device for sharing system resources among multi-container systems
CN109298913A (en) * 2018-09-26 2019-02-01 武芮 The method and device of schedules system resources between a kind of multi-vessel system

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102122255A (en) * 2011-03-15 2011-07-13 合肥华云通信技术有限公司 Method for realizing inter-process communication in Linux system by utilizing virtual character equipment and genetlink
CN104714792A (en) * 2013-12-17 2015-06-17 腾讯科技(深圳)有限公司 Multi-process shared data processing method and device
CN105991755A (en) * 2015-05-21 2016-10-05 杭州迪普科技有限公司 Service message distribution method and service message distribution device
CN105487933A (en) * 2015-11-24 2016-04-13 无锡江南计算技术研究所 Inter-kernel asynchronous message queue and shared memory based inter-domain communication method
CN105978997A (en) * 2016-06-24 2016-09-28 北京百度网讯科技有限公司 Data transmission method and system
CN106648939A (en) * 2016-12-30 2017-05-10 上海寰视网络科技有限公司 Method and equipment for inter-process resource sharing

Also Published As

Publication number Publication date
CN110069346A (en) 2019-07-30

Similar Documents

Publication Publication Date Title
CN110069346B (en) Method and device for sharing resources among multiple processes and electronic equipment
CN111091429A (en) Electronic bill identification distribution method and device and electronic bill generation system
US5734902A (en) Communication system for maintaining data consistency among replicated shared objects
US9749445B2 (en) System and method for updating service information for across-domain messaging in a transactional middleware machine environment
US20190108519A1 (en) Transaction scheduling for block space on a blockchain
KR20160147909A (en) System and method for supporting common transaction identifier (xid) optimization and transaction affinity based on resource manager (rm) instance awareness in a transactional environment
US10838977B2 (en) Key-value replication with consensus protocol
CN110968586A (en) Distributed transaction processing method and device
CN110134503B (en) Timed task processing method and device in cluster environment and storage medium
WO2020215752A1 (en) Graph computing method and device
JP6975153B2 (en) Data storage service processing method and equipment
US20110131288A1 (en) Load-Balancing In Replication Engine of Directory Server
CN108595346B (en) Feature library file management method and device
CN111694639A (en) Method and device for updating address of process container and electronic equipment
CN112596669A (en) Data processing method and device based on distributed storage
US10110670B2 (en) Allocation of service endpoints to servers
CN115033350A (en) Execution method and device of distributed transaction
CN110290215B (en) Signal transmission method and device
CN114205354A (en) Event management system, event management method, server, and storage medium
CN110543351B (en) Data processing method and computer device
CN117742979B (en) Distributed lock method oriented to space-time data processing and electronic equipment
US11768704B2 (en) Increase assignment effectiveness of kubernetes pods by reducing repetitive pod mis-scheduling
CN116405384B (en) Method, system, equipment and storage medium for solving declarative API resource race
CN110879747B (en) Resource management method and device
CN114201465A (en) Data integration method, system, computer device and storage medium

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
GR01 Patent grant
GR01 Patent grant