shmget [ MPE/iX Developer's Kit Reference Manual Volume II ] MPE/iX 5.0 Documentation
MPE/iX Developer's Kit Reference Manual Volume II
shmget
Returns a shared memory identifier.
Syntax
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
int shmget (key_t key, int size, int shmflg);
Parameters
key Passes either a user-defined key value to rendezvous with the
shared memory area, or IPC_PRIVATE. If IPC_PRIVATE is
specified, a new shared memory area is created, but other
processes cannot rendezvous by key. Refer to the description
of ftok() for details about obtaining user-defined key values
size Passes the size, in bytes, of the shared memory area. The
maximum shared memory area size is 256 megabytes.
shmflg Valid flags for this function are:
IPC_CREAT If a shared memory area is not already
associated with key, a new shared memory
area identifier is allocated and a shared
memory area and data structure are
associated with it. If a shared memory area
is already associated with key, shmctl()
returns the shared memory identifier
associated with key.
IPC_EXCL If specified with IPC_CREAT,shmget() returns
an error if a shared memory identifier is
already associated with key.
MODE The lower nine bits of shmflg contain the
access permission bits (similar to the nine
bit mask found in file entries). They
define access permissions for the owner, the
group, and other users on the system.
SHM_NO_PID Allocate a shared memory area without PID
protection. (Refer to "Implementation
Considerations" for more information about
using this flag.)
SHM_PRIV_ACCESS Allocate a shared memory area accessible
only to a calling process that has MPE/iX
user privileged mode (PM). (Refer to
"Implementation Considerations" for more
information about using this flag.)
Return Values
>=0 Success. A shared memory area identifier is returned.
-1 An error occurred, and errno is set to indicate the error
condition.
Description
The shmget() function returns a shared memory identifier associated with
the value passed in key. A new shared memory identifier is allocated and
an associated data structure and shared memory area of size bytes are
associated with it if:
* The value passed in key is equal to IPC_PRIVATE.
* The value passed in key does not already have a shared memory
identifier associated with it, and shmflg specifies IPC_CREAT.
The data structure associated with the new shared memory identifier is
initialized to the following values:
shm_perm.cuid Effective user ID of the calling process (creator user
ID)
shm_perm.uid Effective user ID of the calling process (owner user ID)
shm_perm.cgid Effective group ID of the calling process (creator group
ID)
shm_perm.gid Effective group ID of the calling process (owner group
ID)
shm_perm.mode Low-order 9 bits are set equal to the low-order 9 bits of
shmflg
shm_segsz Value passed in size
msg_qnum Zero
shm_lpid Zero
shm_nattch Zero
shm_atime Zero
shm_dtime Zero
shm_ctime Current time
Implementation Considerations
The maximum shared memory area size is 256 megabytes.
On MPE/iX, two flags, SHM_NO_PID and SHM_PRIV_ACCESS are available to the
shmget() function that are not defined by SVID. (Refer to the description
of shmflg above.)
NOTE The SHM_NO_PID and SHM_PRIV_ACCESS flags are available only on 900
Series HP 3000 computer systems. These two flags are not
recommended for portable applications. Specifying these flags on a
different computer system may produce unpredictable results. In
addition, setting SHM_NO_PID increases the risk of data corruption,
since the shared memory area will not be protected by normal MPE/iX
data memory protection traps.
An MPE/iX system manager can use the MPE/iX SVIPC utility to
interactively configure:
* The minimum and maximum size of the shared memory area
* The total number of shared memory areas allowed system wide.
Refer to the section "Managing SVID IPC Services" for more information.
Errors
If an error occurs, errno is set to one of the following values:
EACCES CAUSE A shared memory identifier exists for key but the
calling process does not have permission (as
specified by the low-order 9 bits of shmflg).
ACTION Ensure that the calling process has appropriate
permissions to obtain access to the existing shared
memory identifier.
EEXIST CAUSE A shared memory identifier exists for key and shmflg
specifies both IPC_CREATE and IPC_EXCL.
ACTION To access the existing shared memory identifier,
remove the IPC_EXCL option. Otherwise, a unique key
value must be specified for a new shared memory
identifier to be created.
EINVAL CAUSE size is either less than the system-defined minimum
or greater than the system-defined maximum, or a
shared memory identifier exists for key and the size
of the shared memory area associated with it is less
than size and size is not equal to zero.
ACTION Check to see that size is within the system-defined
valid range, and that if a shared memory identifier
already exists for key, that size is within that
shared memory area's valid range.
ENOENT CAUSE A shared memory identifier does not exist for key and
shmflg does not specify IPC_CREATE.
ACTION To create a shared memory area for key when one does
not already exist, make sure IPC_CREAT is specified.
ENOMEM CAUSE The available data space is not large enough to
create a shared memory identifier and associated
shared memory area.
ACTION None. The operation can be retried if another shared
memory identifier is removed from the system.
ENOSPC CAUSE The number of shared memory identifiers would exceed
the system-defined limit.
ACTION None. The operation can be retried if another shared
memory identifier is removed from the system.
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
shmat(), shmctl(), shmdt(), SVID2 (Section 12)
MPE/iX 5.0 Documentation