Unix Shared Memory
来源:互联网 发布:java设备管理系统 编辑:程序博客网 时间:2024/05/09 20:24
To use shared memory, include the following:
#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>
Procedure for using Shared Memory
1. Find a key. Unix uses this key for identifying shared memory segments.
A key is a value of type key_t. There are three ways to generate a key:
a) Do it yourself
key_t SomeKey;SomeKey = 1234;
b) Use function ftok()
key_t = ftok(char *path, int ID);Keys are global entities. If other process know your key, they can access your shared memory.
c) Ask the system to provide a private key.
IPC_PRIVATE.
2. Use shmget() to allocate a shared memory.
shm_id = shmget(key_t key,/*identity key */int size,/* memory size */int flag);/* creation or use */The flag is either 0666(rw) or IPC_CREAT.
The following creates a shared memory of size struct Data with a private key IPC_PRIVATE. This is a creation (IPC_CREAT) and permits read and write(0666).
struct Data{int a;double b;int x;};int ShmID;ShmID = shmget(IPC_PRIVATE,/* private key */sizeof(struct Data),/* size */IPC_CREAT | 0666);/* cr & rw */
3. Use shmat() to attach a shared memory to an address space.
4. Use shmdt() to detach a shared memory from an address space.
5. Use shmctl() to deallocate a shared memory.
- Unix Shared Memory
- TECH: Unix Semaphores and Shared Memory Explained (Doc ID 15566.1)
- eXtremeDB shared memory using in Unix-based OS or Windows
- shared memory
- Shared memory
- Shared Memory
- 共享内存 (shared memory)是 Unix下的多进程之间的通信方法
- Linux IPC - Shared memory
- What is Shared Memory?
- [PHP] Shared memory access
- postgresql的shared memory
- Modifying Shared Memory
- Shared Memory Example
- CUDA shared memory
- informix Shared memory 错误
- shared memory driver(1)
- shared memory driver(2)
- shared memory&messae passing
- summary in July <Install qemu>
- BMP简介
- Python中re(正则表达式)模块学习
- 微学苑 java
- Eclipse插件安装、更新、删除
- Unix Shared Memory
- graphical model 概述
- Android构建时需要考虑的问题
- 从Google Calendar取出Scheduler
- python中数组,元组,字典和字符串之间的转换
- 将某个窗口置为前景窗口
- RedHat Enterprise Linux 6.4使用Centos 6 的yum源
- jquery动态效果
- 一 需求分析