Linux inter-process communication (IPC) programming practices (8) use of shared memory-POSIX shared memory (API)
1. Posix provides two methods to share memory areas between unrelated processes:
(1) memory ing file: open the function first, and then
Introduction: System v Shared Memory and shared file mappings allow unrelated processes to share memory areas for IPC communication. But there are some drawbacks to these two technologies: 1. The System V Shared memory model uses keys and
Description
Shared memory is the fastest available IPC format. It allows multiple unrelated (unrelated) processes to access the same part of the Logical Memory.
To transmit data between two processes, shared memory is an extremely efficient solution.
The previous section introduced the knowledge about System V shared memory. Now let's take a look at POSIX shared memory and functions.
Shared Memory is simply a real physical memory area. Some functions can be used to map this area to the address
Http://www.cnblogs.com/dubingsky/archive/2009/06/18/1505841.html
One, what is the shared memory area
The shared memory area is the fastest available form of IPC. It allows multiple unrelated processes to access the same part of the logical memory.
The concept of shared memory areas is now extended to include memory areas that are shared between unrelated processes. POSIX provides two ways to share memory areas between unrelated processes :1. Memory mapped file: Opened by the Open function,
1. Preface All examples of this post are based on the RHEL6.5 platform (Linux kernal:2.6.32-431.el6.i686). 2. Introduction to Shared MemoryThe various inter-process communication methods described earlier in Linux, such as pipe (pipeline), FIFO
Document directory
Standard (ansi c, POSIX, svid, xpg ,...)
Online Documentation (man, info, how-,...)
Storage location of library and header files
Standard (ansi c, POSIX, svid, xpg ,...)
Ansi c: This is the C language standard set by ANSI
The previous section described opening a memory-mapped file by the Open function, and then mapping the resulting descriptor to the current process address space by the MMAP function. This section describes another similar shared memory approach,
1. Create/acquire a shared memory#include #include / * for Mode constants */#include / * for O_* Constants */int Shm_open (const char *name, int oflag, mode_t mode);Parameters:Name: Shared memory names; Oflag: With the Open
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.