United States-English |
|
|
HP-UX Reference > Sshmop(2)HP-UX 11i Version 3: February 2007 |
|
NAMEshmat(), shmdt() — shared memory operations SYNOPSIS#include <sys/shm.h> void *shmat(int shmid, void *shmaddr, int shmflg); int shmdt(void *shmaddr); DESCRIPTIONshmat() attaches the shared memory segment associated with the shared memory identifier specified by shmid to the data segment of the calling process. The segment is attached for reading if (shmflg & SHM_RDONLY) is "true"; otherwise, it is attached for reading and writing. It is not possible to attach a segment for write only. If the shared memory segment has never been attached to by any process prior to the current shmat() call, shmaddr must be specified as zero and the segment is attached at a location selected by the operating system. That location is identical in all processes accessing that shared memory object. Once the operating system selects a location for a shared memory segment, the same location will be used across any subsequent shmat() and shmdt() calls on the segment until it is removed by the IPC_RMID operation of shmctl(). See exceptions for MPAS processes below. If this is not the first shmat() call on the shared memory segment throughout the system, shmaddr must either be zero or contain a nonzero address that is identical to the one returned from previous shmat() calls for that segment. Even if no processes are currently attached to the segment, as long as the segment has been attached before, the same rule applies. See exceptions for MPAS processes below. If the calling process is already attached to the shared memory segment, shmat() fails and returns SHM_FAILED regardless of what value is passed in shmaddr. See exceptions for MPAS processes below. shmdt() detaches from the calling process's data segment the shared memory segment located at the address specified by shmaddr. Exceptions for MPAS ProcessesOn Itanium(R)-based platforms, MPAS (Mostly Private Address Space) processes are not restricted to passing in zero or a fixed value to calls to shmat(). MPAS processes may pass in other addresses. The shmat() call may fail or succeed due to implementation dependent reasons. MGAS processes have all the restrictions outlined above. In addition, an MGAS process may not assume that it can attach at the address that an MPAS process can use to attach to the same segment. An MPAS process may be able to attach to the same shared memory segment multiple times. Success or failure of such an operation is implementation dependent. Failure will be indicated by a return value of SHM_FAILED. An MPAS process should specify IPC_SHARE32 or IPC_GLOBAL flags in the call to shmat(). These follow the same rules as such flags passed to shmget(2). See the Adaptive Address Space Whitepaper for details. RETURN VALUEshmat() returns the following values:
shmdt() returns the following values:
ERRORSIf shmat() fails, errno is set to one of the following values.
If shmdt() fails, errno is set to one of the following values.
EXAMPLESThe following call to shmat() attaches the shared memory segment to the process. This example assumes the process has a valid shmid, which can be obtained by calling shmget(2). char *shmptr; shmptr = (char *) shmat(myshmid, 0, 0); The following call to shmdt() then detaches the shared memory segment. shmdt (shmptr); |
Printable version | ||
|