70 likes | 260 Views
Shared memory in Linux. Creating a shared segment. #include <sys/ ipc.h > #include <sys/ shm.h > shmid =shmget (IPC_PRIVATE, size , IPC_CREAT| 0 666); “size” is the amount of RAM you need “ shmid ” is the ID of the new segment to be shared with children (if < 0 then error)
E N D
Creating a shared segment • #include <sys/ipc.h> • #include <sys/shm.h> shmid=shmget (IPC_PRIVATE, size, IPC_CREAT|0666); • “size” is the amount of RAM you need • “shmid” is the ID of the new segment to be shared with children (if < 0 then error) • Content is initialized to all 0 • NOTE: 0666 is octal notation for: 110110110
Using the segment • #include <sys/types.h> • retval=shmat(shmid, NULL, 0); • shmid is returned from shmget • “retval” is a void *