HP 3000 Manuals

shmat [ MPE/iX Developer's Kit Reference Manual Volume II ] MPE/iX 5.0 Documentation


MPE/iX Developer's Kit Reference Manual Volume II

shmat 

Attaches the calling process to a shared memory area.

Syntax 

     #include <sys/types.h>
     #include <sys/ipc.h>
     #include <sys/shm.h>

     char *shmat (int shmid, char *shmaddr, int shmflg);

Parameters 

shmid      Passes a shared memory identifier returned by a shmget() call.

shmaddr    Passes either 0 or a valid memory address.  Set shmaddr to
           zero to attach a shared memory area to the address space of
           the calling process.  Otherwise, set shmaddr to the data start
           address of a shared memory area that is already attached to
           another process.

shmflg     Passes a value specifying that the calling process has
           read/write access to the attached shared memory area.  It is
           not possible to attach for write-only access or read-only
           access.

Return Values 

addr       Success.  shmat() returns the data area start address of the
           attached shared memory area.

-1         An error occurred, and errno is set to indicate the error
           condition.

Description 

The shmat() function attaches the shared memory area associated with the
shared memory identifier specified by shmid to the data area of the
calling process.

If the shared memory area is already attached to another process, a
non-zero value of shmaddr is accepted, provided the specified address is
identical to the current attach address of the area.  The area is
attached for both reading and writing.

Implementation Considerations 

The MPE/iX implementation of SVID IPC shared memory emulates the
equivalent functionality on a Series 800 HP9000 computer system.  [REV
BEG]A process cannot attach to the same shmid multiple times.[REV END]
The address must be the same in all processes.  Specifying a different
address results in an error.

When attaching to a shared memory area for the first time, shmaddr must
be set to zero.

The SHM_RND and SHMLBA flags are not supported.  Specifying SHM_RND
results in an error, and errno is set to EACCES.

The maximum number of shared memory areas a process can attach to is 256.

When fork() is called, the child process inherits all shared memory areas
to which the parent process is attached.  When exec() is called, the
shared memory attached to the calling process is not attached to the new
process.

Errors 

If an error occurs, errno is set to one of the following values.

EACCES            CAUSE           The calling process does not have permission, or
                                  SHM_RND was specified.

                  ACTION          Ensure that the calling process has permission to
                                  access the area as requested, or do not specify the
                                  SHM_RND and SHMLBA flags.

EINVAL            CAUSE           shmid is not a valid shared memory identifier, or
                                  shmaddr is not zero and not equal to the current
                                  attach location for the shared memory area, or the
                                  calling process is already attached to the shared
                                  memory area.

                  ACTION          Check that shmid is valid and has not been removed
                                  from the system.  If there is no current attach
                                  location for the shared memory area, make sure
                                  shmaddr is zero.  A process cannot attach more than
                                  once (concurrently) to the same shared memory area.

EMFILE            CAUSE           The number of shared memory areas attached to the
                                  calling process would exceed the system-defined
                                  limit.

                  ACTION          None.  The operation can be retried if the process
                                  detaches from another shared memory area to which it
                                  is currently attached.

ENOMEM            CAUSE           The available data space is not large enough to
                                  accommodate the shared memory area.

                  ACTION          None.  The operation can be retried later.

ESYSERR           CAUSE           An operating system error occurred that does not map
                                  directly to any of the above errors.

                  ACTION          Examine the MPE/iX process error stack for the type
                                  of system error.

See Also 

shmctl(), shmdt(), shmget(), SVID2 (Section 12)



MPE/iX 5.0 Documentation