头文件
sys/shm.h
shmget
- 创建共享内存
- 第一次创建完共享内存时,它还不能被任何进程访问
1 | int shmget(key_t key, size_t size, int shmflg); |
shmat — at:attach
- 启动对该共享内存的访问,并把共享内存连接到当前进程的地址空间
1 | void *shmat(int shm_id, const void *shm_addr, int shmflg); |
shmdt — dt:detach
- 将共享内存从当前进程中分离。注意,将共享内存分离并不是删除它,只是使该共享内存对当前进程不再可用
1 | int shmdt(const void *shmaddr); |
shmctl — ctl:control
- 控制共享内存
1 | int shmctl(int shm_id, int command, struct shmid_ds *buf); |