gtpc2m6kC/C++ Language Support User's Guide

shmdt-Detach Shared Memory

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);

shmaddr
The address of the shared memory segment to be detached from the address space of the calling process. This address is returned by the shmat function.

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:

EINVAL
The value of the shmaddr parameter is not the address of the first byte of the shared memory.

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