8 void *shm_setup(int size)
13 shmid = shmget(IPC_PRIVATE, size, SHM_R | SHM_W);
15 printf("can't get shared memory\n");
18 ret = (void *)shmat(shmid, 0, 0);
19 if (!ret || ret == (void *)-1) {
20 printf("can't attach to shared memory\n");
23 /* the following releases the ipc, but note that this process
24 and all its children will still have access to the memory, its
26 means we don't leave behind lots of shm segments after we exit
28 See Stevens "advanced programming in unix env" for details
30 shmctl(shmid, IPC_RMID, 0);
37 int main(int argc, char *argv[])
43 printf("shm_size <size>\n");
49 buf = shm_setup(size);
52 printf("shm_setup(%d) failed\n", size);