Gets shared memory segments.
Standard C Library (libc.a)
#include <sys/shm.h>
int shmget (Key, Size, SharedMemoryFlag)
key_t Key;
size_t Size
int SharedMemoryFlag;
The shmget subroutine returns the shared memory identifier associated with the specified Key parameter.
The following limits apply to shared memory:
Item | Description |
---|---|
Key | Specifies either the IPC_PRIVATE value or an IPC key constructed by the ftok subroutine (or by a similar algorithm). |
Size | Specifies the number of bytes of shared memory required. |
SharedMemoryFlag | Constructed
by logically ORing one or more of the following
values:
Values that begin with the S_I prefix are defined in the sys/mode.h file and are a subset of the access permissions that apply to files. |
if (shmctl (id, IPC_RMID, 0) == -1)
perror ("error in closing segment"),exit (1);
Upon successful completion, a shared memory identifier is returned. Otherwise, the shmget subroutine returns a value of -1 and sets the errno global variable to indicate the error.
The shmget subroutine is unsuccessful if one or more of the following are true:
Item | Description |
---|---|
EACCES | A shared memory identifier exists for the Key parameter, but operation permission as specified by the low-order 9 bits of the SharedMemoryFlag parameter is not granted. |
EEXIST | A shared memory identifier exists for the Key parameter, and both the IPC_CREAT and IPC_EXCL flags are set in the SharedMemoryFlag parameter. |
EINVAL | A shared memory identifier does not exist and the Size parameter is less than the system-imposed minimum or greater than the system-imposed maximum. |
EINVAL | A shared memory identifier exists for the Key parameter, but the size of the segment associated with it is less than the Size parameter, and the Size parameter is not equal to 0. |
ENOENT | A shared memory identifier does not exist for the Key parameter, and the IPC_CREAT flag is not set in the SharedMemoryFlag parameter. |
ENOMEM | A shared memory identifier and associated shared memory segment are to be created but the amount of available physical memory is not sufficient to meet the request. |
ENOSPC | A shared memory identifier will be created, but the system-imposed maximum of shared memory identifiers allowed will be exceeded. |