SHMAT(2,L) AIX Technical Reference SHMAT(2,L)
-------------------------------------------------------------------------------
shmat
PURPOSE
Attaches a shared memory segment to the current process.
SYNTAX
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
char *shmat (shmid, shmaddr, shmflg)
int shmid;
char *shmaddr;
int shmflg;
DESCRIPTION
The shmat system call attaches the shared memory segment associated with the
shared memory identifier (returned by shmget) specified by the shmid parameter
to the address space of the calling process.
The segment is attached at the address specified by the shmaddr parameter as
follows:
o If the shmaddr parameter is equal to 0, the segment is attached at the
first available address as selected by the system.
o If the shmaddr parameter is not equal to 0, and SHM_RND is set in shmflg,
the segment is attached at the next lower segment boundary. This address
given by (shmaddr - (shmaddr module SHMLBA)).
o If the shmaddr parameter is not equal to 0 and SHM_RND not set in shmflg,
the segment is attached at the address given by the shmaddr parameter. If
this address does not point to a segment boundary, then the shmat system
call returns the value -1 and sets errno to EINVAL.
The shmflg parameter specifies several options. Its value is either 0, or is
constructed by logically ORing one or more of the following values:
SHM_RND Rounds the address given by the shmaddr parameter to the next
lower segment boundary, if necessary.
SHM_RDONLY Specifies read-only mode instead of the default read-write mode.
The shared memory segment is attached for reading if SHM_RDONLY is set in
shmflg and if the current process has read permission. If SHM_RDONLY is not
Processed November 7, 1990 SHMAT(2,L) 1
SHMAT(2,L) AIX Technical Reference SHMAT(2,L)
set and the current process has both read and write permission, then it is
attached for reading and writing.
Note: In a Transparent Computing Facility cluster, shared memory segments
exist only on the cluster site on which they are created. Consequently,
processes that use shared memory segments cannot be migrated to other
sites and processes on different cluster sites cannot share memory
segments.
RETURN VALUE
Upon successful completion, the segment start address of the attached shared
memory segment is returned. If shmat fails, a value of -1 is returned and
errno is set to indicate the error.
ERROR CONDITIONS
The shmat system call fails and the shared memory segment is not attached if
one or more of the following are true:
EACCES Operation permission is denied to the calling process.
ENOMEM The available data space in memory is not large enough to hold the
shared memory segment.
EINVAL The shmid parameter is not a valid shared memory identifier.
EINVAL The shmaddr parameter is not equal to 0, and the value of (shmaddr -
(shmaddr module SHMLBA)) is an illegal address.
EINVAL The shmaddr parameter is not equal to 0, SHM_RND is not set in
shmflg, and the the shmaddr parameter is an illegal address.
EINVAL The shmaddr parameter is not equal to 0, SHM_RND is not set in
shmflg, and the the shmaddr parameter does not point to a segment
boundary.
EMFILE The number of shared memory segments attached to the calling process
would exceed the system-imposed limit.
RELATED INFORMATION
In this book: "exec: execl, execv, execle, execve, execlp, execvp," "exit,
_exit," "fork, vfork," "shmctl," "shmdt," and "shmget."
Processed November 7, 1990 SHMAT(2,L) 2