/**
@file shmRemoveRT.c
@author Mitch Richling <http://www.mitchr.me/>
@Copyright Copyright 1998,2000,2004 by Mitch Richling. All rights reserved.
@brief How to delete a shared memory segment@EOL
@Keywords UNIX shared memory
@Std ISOC
This C program is intended to illustrate how one can
delete shared memory segments in UNIX using the
POSIX real-time APIs.
@Tested
- MacOS X.2
*/
#include <stdlib.h> /* Standard Lib ISOC */
#include <stdio.h> /* I/O lib ISOC */
#include <errno.h> /* error stf POSIX */
#include <sys/mman.h> /* mmap() POSIX */
int main(int argc, char *argv[]);
int main(int argc, char *argv[]) {
/* Getting rid of a shared memory segment via the POSIX RT APIs is simple: */
if(shm_unlink("/tmp/foobar") < 0) {
/* I have a case for all of the interesting cases, even the ones
that can not happen in this situation... */
switch(errno) {
case EACCES: printf("shm_unlink failed: Permission is denied to be remove the object.\n");
break;
case ENAMETOOLONG: printf("shm_unlink failed: name exceeded SHM_NAME_MAX characters.\n");
break;
case ENOENT: printf("shm_unlink failed: The named object does not exist.\n");
break;
default: printf("shm_unlink failed: Duno why (%d)...\n", errno);
break;
} /* end switch */
exit(1);
} /* end if */
printf("The shared memory segment was removed.\n");
return 0;
} /* end func main() */
Generated by GNU Enscript 1.6.5.2.