#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) { perror("shmget"); exit(EXIT_FAILURE); } result = (char *)shmat(shmid, NULL, 0); if(result == (char *)-1) { int save_errno = errno; if(shmctl(shmid, IPC_RMID, NULL) == -1) { perror("shmctl"); } errno = save_errno; perror("shmat"); exit(EXIT_FAILURE); } sleep(5); if(shmctl(shmid, IPC_RMID, NULL) == -1) { perror("shmctl"); exit(EXIT_FAILURE); } if(shmdt(result) == -1) { perror("shmdt"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }