Next: shmat, Previous: Shared Memory, Up: Shared Memory
A shared memory segment is allocated by a shmget system call:
int shmget(key_t key, int size, int shmflg);
ftok
or IPC_PRIVATE
A descriptor for a shared memory segment is allocated if there isn't one
corresponding to the given key. The access permissions specified are
then copied into the shm_perm
struct for the segment along with the
user-id etc. The user must use the IPC_CREAT flag or key = IPC_PRIVATE
to allocate a new segment.
If the segment already exists, the access permissions are verified, and a check is made to see that it is not marked for destruction.
size
is effectively rounded up to a multiple of PAGE_SIZE as shared
memory is allocated in pages.
Errors:
EINVAL : (allocate) Size not in range specified above.
(procure) Size greater than size of segment.
EEXIST : (allocate) IPC_CREAT | IPC_EXCL specified and resource exists.
EIDRM : (procure) The resource is marked destroyed or was removed.
ENOSPC : (allocate) All id's are taken (max of SHMMNI id's system-wide).
Allocating a segment of the requested size would exceed the
system wide limit on total shared memory (SHMALL).
ENOENT : (procure) Resource does not exist and IPC_CREAT not specified.
EACCES : (procure) Do not have permission for specified access.
ENOMEM : (allocate) Could not allocate memory for shmid_ds or pg_table.