COHERENT manpages

This page displays the COHERENT manpage for shmat() [Attach a shared-memory segment to a process].

List of available manpages
Index


shmat() -- General Function (libc)

Attach a shared-memory segment to a process
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
char *shmat (shmid, shmaddr, shmflg)
int shmid, shmflag; char *shmaddr;

shmat() attaches  the shared-memory segment associated  with the identifier
shmid with the .data segment of the calling process.

shmat() selects  the address at which to  attach the shared-memory segment.
If

    shmflg & SHM_RDONLY

is true, the attached memory is read-only; otherwise, it is read-write.

shmat() fails if any of the following is true:

-> shmid is  not a valid  shared-memory identifier.  shmat()  sets errno to
   EINVAL.

-> The calling process lacks appropriate permission (EACCES).

-> Not  enough  memory  is  available  to  hold the  shared-memory  segment
   (ENOMEM).

-> The  process already  has the maximum  number of  shared-memory segments
   attached to it (EMFILE).

You can  attach more than one  shared-memory segment to a  process, up to a
maximum of six.  COHERENT assigns each segment its own address.

If all went well, shmat() returns the address of the newly attached shared-
memory segment;  otherwise, it returns -1 and sets  errno to an appropriate
value.

Example

For an example of this function, see the Lexicon entry for shmget().

See Also

libc,
shmctl(),
shmdt(),
shmget()

Notes

The COHERENT implementation of shared memory does not yet support attaching
a shared-memory  segment to a user-defined  address.  Therefore, you should
always set shmaddr to zero.