shmat()

attach shared memory 

Function


SYNOPSIS

#include <sys/shm.h>

void *shmat(int shmid, const void *shmaddr, int shmflg);


DESCRIPTION

The shmat() function attaches the shared memory segment associated with the shared memory identifier shmid to the data segment of the calling process. The segment is attached at the address specified by one of the following criteria:

The segment is attached for reading if (shmflg & SHM_RDONLY) is non-zero and the calling process has read permission, otherwise if (shmflg & SHM_RDONLY) is zero and the calling process has read and write permission, the segment is attached for reading and writing.

Upon successful completion, shmat() increments the value of shm_nattach associated with the shared memory segment.

You must explicitly remove shared memory segments after the last reference to them has been removed.


PARAMETERS

shmid 

Is a unique positive integer created by a shmget() system call and associated with a segment of shared memory.

shmaddr 

Points to the desired address of the shared memory segment.

shmflg 

Specifies a set of flags that indicate the specific shared memory conditions and options to implement.


RETURN VALUES

If successful, shmat() returns the data segment start address of the attached shared memory segment. On failure, it returns -1, does not attach the shared memory segment, and sets errno to one of the following values:

EACCES 

Operation permission is denied to the calling process.

EINVAL 

shmaddr is not equal to zero, and the value of (shmaddr - (shmaddr % SHMLBA)) is an illegal address.

shmaddr is not equal to zero, (shmflg & SHM_RND) is 0, and the value of shmaddr is an illegal address.

shmid is not a valid shared memory identifier.

EMFILE 

The number of shared memory segments attached to the calling process exceeds the system-imposed limit.

ENOMEM 

The available data space is not large enough to accommodate the shared memory segment.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

Windows requires that attached shared memory regions be aligned on 64K boundaries. If you attempt to use shmat() with a fixed address, you must ensure that this address is 64K-aligned.

On Windows 9x, shmat() can only be used to map items to addresses between 0x80000000 and 0xbfffffff. This is because of a limitation of MapViewOfFileEx(), and ultimately, the Windows 9x memory manager. Windows NT has no such limitation.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), exit(), fork(), shmctl(), shmdt(), shmget()


PTC MKS Toolkit 10.5 Documentation Build 40.