Linux Share Memory

Linux Share Memory

Linux Share Memory

1 Introduction

Shared memory is one kinds of mechanism to do effective IPC. There are three kinds of API to share memory among different processes:
  • shmget
  • shm_open
  • tmpfs

2 tmpfs .vs. shm_open

df -h

This command can list the mounted file systems. In general, there will be a record:
 
tmpfs           1.9G  748K  1.9G   1% /dev/shm

tmpfs is one kinds of file system which store the file data in virtual memory instead of hard disk. It can speed up the program which needs temp storage. Because of its file store in virtual memory, It can be used as a shared memory facility.
While according to shm_open's manual, the name parameter of shm_open is actually an object name, not a file path. So I read glibc's source code and find the definition the shm_open, It just concatenate tmpfs path name with the object name, and open it.
In a word, Both tmpfs and shm_open are same stuff.

3 shmget .vs. shm_open

shmget is sysVr4 standard way to share memory, which is old-fashion and may be deprecated. shm_open is the Posix standard, and is the recommended way in linux.

Comments

Popular posts from this blog

Bluedroid stack in android

How to setup a NAT server?

Network programming in elisp