#define _GNU_SOURCE #include #include #include #include #include #include #include #include int main(void) { int shmid = -1; char *result; shmid = shmget(IPC_PRIVATE, 1024*1024, IPC_CREAT|0700); if(shmid == -1) { error(0, errno, "shmget"); exit(1); } result = (char *)shmat(shmid, NULL, 0); if(result == (char *)-1) { int save_errno = errno; if(shmctl(shmid, IPC_RMID, NULL) == -1) { error(0, errno, "shmctl"); } error(0, save_errno, "shmat"); exit(1); } sleep(5); if(shmctl(shmid, IPC_RMID, NULL) == -1) { error(0, errno, "shmctl"); exit(1); } if(shmdt(result) == -1) { error(0, errno, "shmdt"); exit(1); } exit(0); }