shmget() - get shared memory segment
#include <sys/shm.h>
int shmget(key_t key, size_t size, int shmflg)
The shmget(2) function creates a shared memory identifier based upon the argument key. The function creates an identifier, data structure, and shared memory segment if:
The new shared memory segment is at least size bytes large. The permission mode (the low-order nine bits of the member shm_perm.mode) are set to the low-order nine bits of shmflg.
If there is already a shared memory segment associated with key, the function returns the identifier for that shared memory segment if the permissions on that shared memory segment allow the calling process to make use of it. If the permissions do not allow it, the function fails. See the errors [EACCES] and [EEXIST].
The members of the data structure associated with the shared memory identifier (described in <sys/shm.h>) are initialized as:
shm_atime | Zero |
shm_ctime | Current time |
shm_dtime | Zero |
shm_lpid | Zero |
shm_nattch | Zero |
shm_perm.cgid | Effective group ID of calling process |
shm_perm.cuid | Effective user ID of calling process |
shm_perm.gid | Effective group ID of calling process |
shm_perm.uid | Effective user ID of calling process |
Low-order nine bits of shm_perm.mode | Low-order nine bits of shflg |
shm_segsz | Value of size |
The header file <sys/shm.h> includes <sys/ipc.h>.
On success, the shmget(2) function returns a shared memory identifier (a non-negative integer).
On failure, shmget(2) returns -1 and sets errno
The shmget(2) function can fail for the following reasons:
(shmflg&IPC_CREAT)&&(shmflg&IPC_EXCL)
is non-zero.shmat(2)
shmctl(2)
shmdt(2)