Copyright (C) 2000-2012 |
Manpages SHMGETSection: Linux Programmer's Manual (2)Updated: 1993-11-28 Index Return to Main Contents NAMEshmget - allocates a shared memory segmentSYNOPSIS#include <sys/ipc.h>#include <sys/shm.h> int shmget(key_t key, int size, int shmflg); DESCRIPTIONshmget() returns the identifier of the shared memory segment associated to the value of the argument key. A new shared memory segment, with size equal to the round up of size to a multiple of PAGE_SIZE, is created if key has value IPC_PRIVATE or key isn't IPC_PRIVATE, no shared memory segment is associated to key, and IPC_CREAT is asserted in shmflg (i.e. shmflg&IPC_CREAT isn't zero). The presence inshmflg is composed of:
If a new segment is created, the access permissions from shmflg are copied into the shm_perm member of the shmid_ds structure that defines the segment. The shmid_ds structure:
struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ int shm_segsz; /* size of segment (bytes) */ time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ unsigned short shm_cpid; /* pid of creator */ unsigned short shm_lpid; /* pid of last operator */ short shm_nattch; /* no. of current attaches */ };
struct ipc_perm { key_t key; ushort uid; /* owner euid and egid */ ushort gid; ushort cuid; /* creator euid and egid */ ushort cgid; ushort mode; /* lower 9 bits of shmflg */ ushort seq; /* sequence number */ }; Furthermore, while creating, the system call initializes the system shared memory segment data structure shmid_ds as follows:
If the shared memory segment already exists, the access permissions are verified, and a check is made to see if it is marked for destruction. SYSTEM CALLS
RETURN VALUEA valid segment identifier, shmid, is returned on success, -1 on error.ERRORSOn failure, errno is set to one of the following:
NOTESIPC_PRIVATE isn't a flag field but a key_t type. If this special value is used for key, the system call ignores everything but the lowest order 9 bits of shmflg and creates a new shared memory segment (on success).The followings are limits on shared memory segment resources affecting a shmget call:
The implementation has no specific limits for the per process maximum number of shared memory segments (SHMSEG). BUGSUse of IPC_PRIVATE doesn't inhibit to other processes the access to the allocated shared memory segment.As for the files, there is currently no intrinsic way for a process to ensure exclusive access to a shared memory segment. Asserting both IPC_CREAT and IPC_EXCL in shmflg only ensures (on success) that a new shared memory segment will be created, it doesn't imply exclusive access to the segment. CONFORMING TOSVr4, SVID. SVr4 documents an additional error condition EEXIST. Neither SVr4 nor SVID documents an EIDRM condition.SEE ALSOftok(3), ipc(5), shmctl(2), shmat(2), shmdt(2)
IndexThis document was created by man2html, using the manual pages. Time: 01:58:18 GMT, January 21, 2025 |