gtpc2m6k | C/C++ Language Support User's Guide |
This function detaches the shared memory segment located at the specified address from the address space of the calling process.
Format
#include <sys/shm.h> type shmdt(const void *shmaddr);
Normal Return
If successful, the shmdt function returns a value of 0 and the value of shm_nattach in the shmid_ds data structure is decremented by 1.
Error Return
If unsuccessful, the shmdt function returns a value of -1 and sets errno to the following:
Programming Considerations
Examples
The following example attaches shared memory to the address space of the calling process by using the shared memory identifier returned by the shmget function. The shared memory identifier is removed from the TPF system by using the shmctl function when it is no longer needed.
#include <sys/ipc.h> #include <sys/shm.h> int main() { cpmst *addr; key_t i; int shm; /** addr is gotten via a shmat **/ i = ftok("/usr",3); shm = shmget(i,8000,IPC_CREAT+S_IRUSR+S_IWUSR); addr = shmat(shm,NULL,0); i = shmdt(addr); }
Related Information