A method, system, terminal and storage medium for sharing data between processes
By creating custom input segments in a multi-process system architecture and using memory mapping files to map target segment data to process address space, the problem that global variables cannot communicate between processes is solved, efficient inter-process data sharing is achieved, and development efficiency and code quality are improved.
Patent Information
- Application Number
- CN202111487234.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-07
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2041-12-07
AI Technical Summary
In a multi-process system architecture, global variables defined in programs cannot communicate between processes. The traditional shared memory communication method requires calling multiple system call interfaces, resulting in low development efficiency, low flexibility and scalability.
By creating custom input segments and using memory map files, the target segment data to be shared is mapped to the process address space to achieve inter-process data sharing. This method reduces the steps of system calls, improves development efficiency, and encapsulates the initialization process so that developers do not need to pay attention to the initialization process.
It improves the development efficiency of data sharing among processes, simplifies the initialization process, improves code quality, and reduces the impact of normal use of other data segments caused by insufficient resources.
Smart Images

Figure CN114296951B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method, system, terminal and storage medium for sharing data between processes. Background Art
[0002] The Linux operating system is often required in program development, and a process is an application running in the operating system and is also an independent resource allocation unit. In the existing Linux operating system, each process has a different user address space, and the resources between different processes are independent and unrelated. Therefore, the global variables of any process cannot be seen in another process, and the resources of another process cannot be directly accessed in one process. However, data interaction is required between different processes, such as data transmission, resource sharing, event notification, etc., so inter-process communication is required.
[0003] To exchange data between processes, they must go through the kernel. A buffer is opened in the kernel. One process copies data from the user address space to the kernel buffer, and the other process reads the data from the kernel buffer. Currently, to complete data exchange between processes, special methods provided by the operating system are required, including four communication methods: pipes, signals, sockets, and shared memory:
[0004] (1) The essence of a pipeline is that the kernel uses a circular queue data structure to implement a kernel buffer. The read and write positions are automatically increased and cannot be changed at will. A piece of data can only be read once, and the data will be removed from the buffer after reading. When the buffer is empty or full, there are certain rules to control the corresponding reading process or writing process to enter the waiting queue. When new data is written to an empty buffer or data is read from a full buffer, the process in the waiting queue is awakened to continue reading and writing.
[0005] However, the limitation of pipelines is that they use half-duplex communication and have limited buffer size, which makes them inefficient when large amounts of data need to be transmitted or processed.
[0006] (2) Signals are a simulation of the interrupt mechanism at the software level and are also a form of asynchronous communication. Signals can be sent to a process at any time without knowing the state of the process. Signals can also interact directly between kernels in the user address space, using signals to notify processes in the user address space of system events that have occurred.
[0007] However, the signal communication method is relatively complex and is not suitable for inter-process communication in general scenarios.
[0008] (3) The difference between sockets and the other three communication methods is that they can be used for process communication between different machines, but sockets are subject to the influence of network fluctuations and have poor stability during data transmission.
[0009] (4) Shared memory is a process where different processes map their virtual memory to the same physical memory. Although this shared memory is created by one process, it can be accessed by multiple processes. Before using the shared memory, the system needs to call each piece of shared memory to complete operations such as creation, attachment, property setting, and removal. However, it is more efficient than the other three communication methods.
[0010] In the process of implementing this application, the inventor found that there are at least the following problems in this technology: in the multi-process system architecture scenario, the global variables defined in the program cannot communicate between processes, and the traditional shared memory communication method requires calling multiple system call interfaces, which requires a large workload in the process of implementing data interaction initialization, and has low flexibility and scalability, resulting in low development efficiency. Further improvements are needed. Summary of the invention
[0011] In order to improve development efficiency in a multi-process system architecture scenario, the present application provides a method, system, terminal, and storage medium for sharing data between processes.
[0012] In a first aspect, the present application provides a method for sharing data between processes, using the following technical solution:
[0013] A method for sharing data between processes, the method comprising the following steps:
[0014] Create a custom input segment for storing the target segment data to be shared;
[0015] The target segment data to be shared is placed in a custom input segment, and the target segment data to be shared is mapped to the process address space by means of a memory mapping file, so as to realize data sharing between processes.
[0016] By adopting the above technical solution, the created custom input segment can be separated from the system's default segment area, so that system resources can be more concentrated to complete the data sharing function, reducing the situation where insufficient resources affect the normal use of other data segments; and by using the memory address mapping file method, the system call steps can be reduced, and the address space of the target segment data to be shared can be directly operated, thereby improving development efficiency; at the same time, the initialization process is encapsulated so that developers can realize data sharing between processes without paying attention to the initialization process, thereby further improving development efficiency.
[0017] Optionally, the creation of a custom input segment for storing target segment data to be shared is a custom input segment with a section attribute created by using a GCC compiler.
[0018] By adopting the above technical solution, the GCC compiler can be used to convert the source code in the form of user text into machine code that can be directly executed by the computer, and the section attribute can provide the permission to access the identification object.
[0019] Optionally, the step of placing the target segment data to be shared into a custom input segment specifically includes:
[0020] By adding an attribute for changing the characteristics of the target segment data to be shared before the target segment data to be shared, the target segment data to be shared is placed in the custom input segment.
[0021] By adopting the above technical solution, by adding an attribute for changing the declared data characteristics in the target segment data to be shared, the target segment data to be shared can be mapped to the custom input segment.
[0022] Optionally, mapping the target segment data to be shared to the process address space by means of a memory mapping file specifically includes:
[0023] Modify the link script to add a modification segment for modifying the location of the target segment data to be shared, wherein the memory address space of the modification segment is located above the memory address space of the ".bss" data segment;
[0024] The system call interface is called to implement mapping the target segment data to be shared into the process address space.
[0025] By adopting the above technical solution, modifying the link script can modify the position of the target segment data to be shared, so that the target segment data to be shared is placed in the correct position of the custom input segment; and calling the system call interface can realize mapping the target segment data into the process address space.
[0026] Optionally, the modification segment specifically includes:
[0027] An alignment line for aligning a memory page boundary, wherein the memory page boundary is aligned to 0x1000 bytes;
[0028] A starting segment for identifying a starting address of the target segment data to be shared;
[0029] and an end segment for identifying the end address of the target segment data to be shared, wherein the end segment is located after the start segment.
[0030] By adopting the above technical solution, the alignment line can align the boundary of the memory page with 0x1000 bytes, thereby improving storage efficiency; the start segment can identify the start address of the target segment data to be shared; at the same time, the end segment can identify the end address of the target segment data to be shared.
[0031] Optionally, calling a system call interface to implement mapping the target segment data to be shared to a process address space specifically includes:
[0032] Calling the mmap function interface to create a memory mapping area, wherein the parameter values of the mmap function interface include "start" for setting the starting address of the memory mapping area, "length" for setting the length of the memory mapping area, "prot" for setting the file permissions of the memory mapping area, and "flags" for setting the memory mapping object type of the memory mapping area;
[0033] Modify the parameter values of the mmap function interface, wherein the "start" is set to the starting address of the custom input segment; the "length" is set to the length of the custom input segment; the "prot" is set to be readable and writable; and the "flags" is set to shared memory between processes, so that the target segment data to be shared and all processes mapped to the target segment data to be shared share the same mapping space.
[0034] By adopting the above technical solution, calling the mmap function interface can create a memory mapping area, thereby realizing shared memory; at the same time, it can reduce system call operations such as read and write, thereby improving development efficiency.
[0035] Optionally, after creating a custom input segment with a section attribute, obtaining the address range of the custom input segment; after mapping the target segment data to be shared to the process address space by using the memory mapping file, obtaining the address range of the memory address mapping file; comparing the address range of the custom input segment with the address range of the memory address mapping file; if the address range of the custom input segment is within the address range of the memory address mapping file, then the custom input segment is located in the shared mapping space.
[0036] By adopting the above technical solution, the address range of the custom input segment is compared with the address range of the memory address mapping file to check the code, thereby improving the quality of the code and reducing code defects, while shortening the time to discover errors and reducing development costs.
[0037] In a second aspect, the present application provides a system for sharing data between processes, which adopts the following technical solution:
[0038] A system for sharing data between processes, the system comprising:
[0039] Compile build module: Create custom input segments for storing target segment data to be shared;
[0040] Mapping module: puts the target segment data to be shared into the custom input segment, and maps the target segment data to be shared to the process address space by means of a memory mapping file, so as to realize data sharing between processes.
[0041] By adopting the above technical solution, the created custom input segment can be separated from the system's default segment area, so that system resources can be more concentrated to complete the data sharing function, thereby reducing the situation where insufficient resources affect the normal use of other data segments; by using the memory address mapping file method, the system call steps can be reduced, and the address space of the target segment data to be shared can be directly operated, thereby improving development efficiency; the initialization process is encapsulated so that developers can realize data sharing between processes without paying attention to the initialization process, thereby further improving development efficiency.
[0042] In a third aspect, the present application provides a smart terminal, which adopts the following technical solution:
[0043] An intelligent terminal comprises a memory and a processor, wherein the memory stores a computer program which can be loaded by the processor and execute the above method.
[0044] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution: a computer-readable storage medium, which stores a computer program that can be loaded by a processor and execute the above method.
[0045] In summary, the present application includes at least one of the following beneficial technical effects:
[0046] 1. By using the memory address mapping file method, the steps of system calls can be reduced, and the address space of the target segment data to be shared can be directly operated, thereby improving development efficiency; and by encapsulating the initialization process, developers can realize data sharing between processes without paying attention to the initialization process, thereby further improving development efficiency.
[0047] 2. Comparing the address range of the custom input segment with the address range of the memory address mapping file can check the code and improve the quality of the code. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a flow chart of a method for sharing data between processes in an embodiment of the present application.
[0049] Figure 2 It is a schematic diagram of the memory address space in the embodiment of the present application.
[0050] Figure 3 It is a schematic diagram of the memory address space in the embodiment of the present application.
[0051] Figure 4 It is a schematic diagram of process memory distribution in an embodiment of the present application.
[0052] Figure 5 It is a sub-flow chart of S2 in the embodiment of the present application.
[0053] Figure 6 It is a sub-flow chart of S23 in the embodiment of the present application.
[0054] Figure 7 It is a schematic diagram of a memory mapping file in an embodiment of the present application.
[0055] Figure 8 It is a flowchart of checking a custom input segment in an embodiment of the present application.
[0056] Fig. 9 It is a flowchart of checking global variables in an embodiment of the present application.
[0057] Fig.10 It is a structural block diagram of a system for sharing data between processes in an embodiment of the present application.
[0058] Description of reference numerals:
[0059] 1. Compile and build modules; 2. Map modules. DETAILED DESCRIPTION
[0060] In order to make the purpose, technical solutions and advantages of this application more clear, the following Figure 1-10 It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0061] The embodiment of the present application discloses a method for sharing data between processes.
[0062] like Figure 1 As shown, the method comprises the following steps:
[0063] S1, creating a custom input segment for storing the target segment data to be shared;
[0064] Specifically, the GCC compiler is used to create a custom input segment with section attributes; the GCC compiler is a programming language translator developed by GNU, which is suitable for multi-process system architecture scenarios and has been adopted as a standard compiler by the Linux operating system; in the process of compiling the program source code, the source code in the user's text form is converted into machine code that can be directly executed by the computer. The machine code is an executable file, that is, a program.
[0065] Generally speaking, the segment used to store programs is called a program segment. After the program source code is compiled, the program source code includes program instructions and program data, and the program data is located in the program segment. In the von Neumann architecture, it is stipulated that a process must include a code segment, which belongs to the program instructions. Figure 2 As shown, at this time, the memory address space of the process is from the highest memory address to the lowest memory address, which is the "Other data" data segment, the ".comment" data segment, the ".bss" data segment, the ".data" data segment and the ".text" data segment, among which the ".comment" data segment, the ".bss" data segment, the ".data" data segment and the ".text" data segment all belong to the program segment.
[0066] By default, after the target file is compiled by the GCC compiler, the code will be placed in the ".text" data segment, and the initialized global variables and static variables will be placed in the ".data" data segment, and the uninitialized global variables and static variables will be placed in the ".bss" data segment.
[0067] The section attribute is used to identify a section of an object and provide access rights to the attributes of the section. In this embodiment, in order to facilitate identification of the custom input section, the custom input section is named "custom_name", such as Figure 2 and Figure 3 As shown, the location of the custom input segment in the memory address space is between the ".bss" data segment and the ".data" data segment.
[0068] like Figure 4 As shown in the figure, "system" represents the system process, "stack" represents the stack, "sharedlibraries" represents the linked shared library, "heap" represents the heap, and ".custom_name" represents the custom input segment, and ".text" represents the code segment. At this time, the process memory distribution from the highest memory address to the lowest memory address is "system", "stack", "shared libraries", "heap", ".custom_name", ".data" and ".text".
[0069] S2, puts the target segment data to be shared into the custom input segment, and uses the memory mapping file method to map the target segment data to be shared to the process address space to realize data sharing between processes.
[0070] In this embodiment, the target segment data to be shared is a global variable, thereby reducing the situation of calling a large amount of data and improving the flexibility and extensibility of the code; in other embodiments, the target segment data to be shared may also be a function;
[0071] like Figure 5 As shown, S2 includes three sub-steps, S21, S22 and S23, specifically including:
[0072] S21, adding an attribute for changing the characteristics of the target segment data to be shared before the target segment data to be shared.
[0073] In this embodiment, the attribute is “_attribute_(section("name"))”; since the custom input section is named “custom_name”, name is custom_name, that is, the attribute is “_attribute_(section("custom_name"))”.
[0074] In the GCC compiler, the "_attribute_" attribute is used to change the characteristics of the target segment data to be shared, while the "_attribute_(section("custom_name"))" attribute is used to put the target segment data to be shared into a custom input segment named "custom_name".
[0075] Therefore, after adding the "_attribute_(section("name"))" attribute to the target segment data to be shared, the target segment data to be shared can be mapped to the custom input segment.
[0076] S22, modify the link script and add the modification section.
[0077] In this embodiment, the link script is an lds file. In other embodiments, the link script can also be a scatter file. Generally speaking, creating an executable program requires preprocessing, compilation, assembly, and linking. In the linking stage, ld or the GCC compiler indirectly calls ld to complete it. The lds file plays a role in the linking stage. The lds file is a link script that plays a role in link positioning.
[0078] In this embodiment, the code for modifying the lds file is "ld-verbose>femor.lds", which is used to generate a .lds file with default link information; in other embodiments, it can also be "gcc femor_section.c-lrt-T femor.lds", which is the compilation instruction of the GCC compiler, where "femor_section.c" is the source code, "-T" is used to specify the lds option, and "-lrt" indicates the library required for linking, and "femor.lds" indicates the lds link script.
[0079] By modifying the lds file, the linking process after the entire program is compiled is defined, the location of each segment of the executable program is determined, and the target segment data to be shared is placed in the correct location of the custom input segment.
[0080] The memory address space of the modified segment is located above the memory address space of the ".bss" data segment.
[0081] As shown in Table 1, the modified segment specifically includes an alignment line, a start segment, and an end segment located after the start segment. In Table 1, ".=ALIGN(0x1000);" is the code for the alignment line; "__custom_name_start=.;" is the code for the start segment; and "__custom_name_end=.;" is the code for the end segment.
[0082] Table 1
[0083] Code snippet for modifying segment:
[0084] .=ALIGN(0x1000); __custom_name_start = .; .custom_name:{*(.custom_name)}; .=ALIGN(0x1000); __custom_name_end = .; .=ALIGN(0x1000);
[0085] In the alignment line, since the default page size of the Linux operating system is 4KB, and the starting address specified by the memory mapping must fall on the page boundary, in this embodiment, the memory page boundary is aligned with 0x1000 bytes; therefore, the code of the alignment line is ".=ALIGN(0x1000);", and the role of the alignment line is to prepare for subsequent memory mapping; in other embodiments, if the page size is not 4KB, the alignment byte of the memory page boundary is adjusted according to the actual situation; the role of the starting segment is to identify the starting address of the target segment data to be shared; the role of the ending segment is to identify the ending address of the target segment data to be shared.
[0086] S23, calling the system call interface to map the target segment data to be shared into the process address space.
[0087] like Figure 6 As shown, S23 includes two sub-steps, S231 and S232, which specifically include:
[0088] S231, call the mmap function interface.
[0089] Generally speaking, the mmap function interface is a system call interface. After calling the mmap function interface, a memory mapping area can be created, so that processes can map to the same ordinary file. At the same time, the data content of the ordinary file can be mapped to the memory mapping area, and the memory mapping area can be read and modified to realize the reading and modification of the file data content, thereby realizing shared memory.
[0090] After ordinary files are mapped to the process address space, the process can access the ordinary files mapped to the process address space in the same way as accessing ordinary memory, eliminating the need to call system call operations such as read and write, thus reducing processing steps and improving development efficiency.
[0091] The specific mmap function interface is "void*mmap(void*addr,size_t length,int prot,intflags,int fd,off_t offset);" where the parameter value "start" indicates the starting address of the memory mapping area; the parameter value "length" indicates the length of the memory mapping area; the parameter value "prot" indicates the file permissions of the memory mapping area; the parameter value "flags" indicates the memory mapping object type of the memory mapping area, and the memory mapping object type is divided into two situations: shareable and non-shareable.
[0092] S232, modify the parameter value of the mmap function interface.
[0093] Specifically, set the parameter value "start" to the starting point of the custom input segment, set the parameter value "length" to the length of the custom input segment, set the parameter value "prot" to readable and writable, and at the same time, set the parameter value "flags" to shared memory between processes, so that the target segment data to be shared and all processes mapped to the target segment data to be shared share the same mapping space.
[0094] like Figure 7 As shown in the figure, "File memory mapping" represents a memory-mapped file. The custom input segment in process A and the custom input segment in process B are both mapped to the memory-mapped file, thereby realizing data sharing between different processes.
[0095] In order to verify the quality of the code and reduce code defects, check whether the custom input segment is located in the shared mapping space.
[0096] like Figure 8As shown, checking whether the custom input segment is located in the shared mapping space includes three sub-steps S31, S32 and S33, specifically including:
[0097] S31, obtaining the address range of the custom input segment.
[0098] In this embodiment, sub-step S31 is executed after creating the custom input section of the section attribute, and the specific acquisition code is "readelf -S a.out", where "a.out" represents an executable program.
[0099] The inventor has performed a series of acquisition processing on the address range in the embodiment of the present application, as follows: As can be seen from Table 2, a new custom input segment named ".custom_name" is added to the program. The starting address of the custom input segment is 0x602000, and the ending address is the starting address of the ".bss" data segment, which is 0x605000.
[0100] Table 2
[0101] The address of the executable program:
[0102]
[0103] S32, obtaining the address range of the memory address mapping file.
[0104] In this embodiment, sub-step S32 is executed after mapping the target segment data to be shared to the process address space by using the memory mapping file. The specific code for checking the process memory distribution is "cat / proc / <pid> / maps", in other embodiments, the code can also be "pmap-x <pid>”.
[0105] S33, compare the address range of the custom input segment with the address range of the memory address mapping file.
[0106] Specifically, if the address range of the custom input segment is within the address range of the memory address mapping file, the custom input segment is located in the shared mapping space.
[0107] As can be seen from Table 3, when viewing the process memory distribution maps, it can be seen that the address space of the mapping file " / dev / shm / file_memory_share" is based on the range of 0x602000-0x605000, and the range of 0x602000-0x605000 is the address range of the custom input segment;
[0108] In Table 3, "rw-s" indicates that the attributes of the memory block are readable, writable, and shared.
[0109] Table 3
[0110] A fragment of the address range of a process's memory mapped file:
[0111] 00602000-00605000 rw-s 00000000 00:13 2373324 / dev / shm / file_memory_share 00605000-0060a000 rw-p 00000000 00:00 0[heap]
[0112] The inventors conducted a series of tests on the global variables in the embodiments of the present application, as follows:
[0113] like Fig. 9 As shown, checking whether the global variable is located in the custom input segment includes four sub-steps S41, S42, S43 and S44, specifically including:
[0114] S41, creating a variable located in the target segment data to be shared.
[0115] In this embodiment, sub-step S41 is executed after mapping the target segment data to be shared to the process address space. Specifically, a variable is created by macro definition. The specific code for creating the variable is shown in Table 3.
[0116] Table 4 Code snippet for creating variables:
[0117] #define__share__attribute__((section("custom_name"))) int__share value = 1;
[0118] In other embodiments, variables may also be defined as shown in Table 5.
[0119] Table 5
[0120] Code snippet to create the variable:
[0121]
[0122]
[0123] In Table 5, "int value = 1;" indicates that a global variable is defined, and "int__attribute__((section("custom_name")))value = 1;" indicates that a global shared variable is defined.
[0124] S42, obtaining the address range of the variable.
[0125] Specifically, check the address range of value.
[0126] S43, obtaining the address range of the custom input segment.
[0127] The specific acquisition code is "readelf -S a.out".
[0128] S44, compares the address range of the variable with the address range of the custom input segment.
[0129] Specifically, if the address range of the variable is within the address range of the custom input segment, the variable is a global shared variable.
[0130] In general, the value variable defined using the section attribute will be placed in the custom input segment named "custom_name", that is, the address of value will be within the address range of the custom input segment, indicating that value is shared between processes, so value is a global shared variable.
[0131] The implementation principle of the embodiment of the present application is: use the GCC compiler to create a custom input segment with a section attribute, put the target segment data to be shared into the custom input segment through a memory address mapping file, and realize the shared mapping of the custom input segment.
[0132] Based on the above method, an embodiment of the present application also discloses a system for sharing data between processes.
[0133] like Fig.10 As shown, the system includes the following modules:
[0134] Compile build module 1: Create a custom input segment for storing the target segment data to be shared;
[0135] Mapping module 2: put the target segment data to be shared into the custom input segment, and use the memory mapping file to map the target segment data to be shared to the process address space to realize data sharing between processes.
[0136] The embodiment of the present application also discloses a smart terminal.
[0137] Specifically, the intelligent terminal includes a memory and a processor, and the memory stores a computer program that can be loaded by the processor and execute the above-mentioned method for sharing data between processes.
[0138] The embodiment of the present application also discloses a computer-readable storage medium.
[0139] The storage medium stores a computer program that can be loaded by a processor and execute the above-mentioned method of data sharing between processes. The storage medium includes: a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0140] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, all equivalent changes made according to the methods, principles, and structures of the present application should be included in the protection scope of the present application.< / pid> < / pid>
Claims
1. A method for sharing data between processes, characterized in that: The method comprises the following steps: Create a custom input segment for storing the target segment data to be shared; The target segment data to be shared is placed in a custom input segment, and the target segment data to be shared is mapped to the process address space by means of a memory mapping file, so as to realize data sharing between processes; the target segment data to be shared is mapped to the process address space by means of a memory mapping file, specifically including: Modify the link script to add a modification segment for modifying the location of the target segment data to be shared, wherein the memory address space of the modification segment is located above the memory address space of the ".bss" data segment; Calling a system call interface to implement mapping of the target segment data to be shared to the process address space; wherein the method further comprises: creating a variable located in the target segment data to be shared; obtaining an address range of the variable; Get the address range of the custom input section; compare the address range of the variable with the address range of the custom input section.
2. The method for sharing data between processes according to claim 1, characterized in that: The custom input segment created for storing the target segment data to be shared is a custom input segment with a section attribute created by using a GCC compiler.
3. The method for sharing data between processes according to claim 1, characterized in that: The step of placing the target segment data to be shared into the custom input segment specifically includes: By adding an attribute for changing the characteristics of the target segment data to be shared before the target segment data to be shared, the target segment data to be shared is placed in the custom input segment.
4. The method for sharing data between processes according to claim 1, characterized in that: The modified section specifically includes: An alignment line for aligning a memory page boundary, wherein the memory page boundary is aligned to 0x1000 bytes; A starting segment for identifying a starting address of the target segment data to be shared; and an end segment for identifying the end address of the target segment data to be shared, wherein the end segment is located after the start segment.
5. The method for sharing data between processes according to claim 1, characterized in that: The calling system call interface realizes mapping the target segment data to be shared to the process address space, specifically including: Calling the mmap function interface to create a memory mapping area, wherein the parameter values of the mmap function interface include "start" for setting the starting address of the memory mapping area, "length" for setting the length of the memory mapping area, "prot" for setting the file permission of the memory mapping area, and "flags" for setting the memory mapping object type of the memory mapping area; Modify the parameter values of the mmap function interface, wherein the "start" is set to the starting address of the custom input segment; the "length" is set to the length of the custom input segment; the "prot" is set to be readable and writable; and the "flags" is set to shared memory between processes, so that the target segment data to be shared and all processes mapped to the target segment data to be shared share the same mapping space.
6. The method for sharing data between processes according to claim 2, characterized in that: After creating a custom input section of the section attribute, obtaining the address range of the custom input section; After mapping the target segment data to be shared to the process address space by using the memory mapping file, obtaining the address range of the memory address mapping file; The address range of the custom input segment is compared with the address range of the memory address mapping file. If the address range of the custom input segment is within the address range of the memory address mapping file, the custom input segment is located in the shared mapping space.
7. A system for sharing data between processes, used to implement the method for sharing data between processes as claimed in any one of claims 1 to 6, characterized in that: The system comprises, Compile build module (1): Create a custom input segment for storing the target segment data to be shared; Mapping module (2): puts the target segment data to be shared into the custom input segment, and maps the target segment data to be shared into the process address space by means of a memory mapping file, so as to realize data sharing between processes.
8. An intelligent terminal, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Multi-process data sharing method and device
CN104881330A