Go to the previous, next section.
int shmget(key_t key, int size, int shmflg);
key: [in] the shared memory segment identificator.
size: [in] size of the segment.
shmflg: [in] flags (see description).
Gets a shared memory segment identifier. If key is
IPC_PRIVATE
, a new segment is created. Otherwise, the result
depends on the value of shmflg:
IPC_CREAT
IPC_EXCL
The value of size
is rounded up to a multiple of PAGE_SIZE
.
The 9 lower bits of shmflg specify the permission bits of the new segment. They have the same layout and meaning as those for files. However, the execute permissions are meaningless for segments.
When creating a segment the system sets the appropriate parameters in
the shmid_ds
structure associated with the new segment. When
accessing an already existing segment, the system simply check if the
segment can be accessed.
On success, the call returns the new shared memory segment
identificator. On error -1 is returned and errno
is set to one of
the following values:
EACCESS
: the task has no access permission to the segment.
EEXIST
: IPC_CREAT
and IPC_EXCL
were specified
and the segment already exists.
EIDRM
: the segment no longer exists in the system.
ENOENT
: the segment never existed.
ENOSPC
: the maximum number of shared memory segment for the
system has been reached.
EINVAL
: size is outside the range [SHMMIN,SHMMAX] or
is greater than the size of the segment (in the case where it already exists).
ENOMEM
Go to the previous, next section.