Listing 1. Allocating Shared Memory Blocks

if ((memid = shmget(IPC_PRIVATE,
     memreq + sizeof(CtrlBlk_T),
     0660)) == -1) {
   fprintf(stderr,
     "%s: shmget failed to allocate %ld bytes.\n"
     "Insufficient memory or absent SYSV IPC "
     "support?\n",
   argv[0], memreq);
   exit(-1);
}
data = (char *)shmat(memid, (char *)0, 0);
shmctl(memid, IPC_RMID, NULL); /* Make shared
                           * memory transient */