'\" te .\" Copyright 1989 AT&T .\" Portions Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. .TH shmget 2 "23 Sep 2015" "SunOS 5.11" "System Calls" .SH NAME shmget, shmget_osm \- get shared memory segment identifier .SH SYNOPSIS .LP .nf #include #include #include \fBint\fR \fBshmget\fR(\fBkey_t\fR \fIkey\fR, \fBsize_t\fR \fIsize\fR, \fBint\fR \fIshmflg\fR); \fBint\fR \fBshmget_osm\fR(\fBkey_t\fR \fIkey\fR, \fBsize_t\fR \fIsize\fR, \fBint\fR \fIshmflg\fR, \fBsize_t\fR \fIgranule_size\fR); .fi .SH DESCRIPTION .sp .LP The \fBshmget()\fR and \fBshmget_osm()\fR functions return the shared memory identifier associated with \fIkey\fR. .sp .LP A shared memory identifier and associated data structure and shared memory segment of at least \fIsize\fR bytes (see \fBIntro\fR(2)) are created for \fIkey\fR if one of the following are true: .RS +4 .TP .ie t \(bu .el o The \fIkey\fR argument is equal to \fBIPC_PRIVATE\fR. .RE .RS +4 .TP .ie t \(bu .el o The \fIkey\fR argument does not already have a shared memory identifier associated with it, and (\fIshmflg\fR\fB&IPC_CREAT\fR) is true. .RE .sp .LP Upon creation, the data structure associated with the new shared memory identifier is initialized as follows: .RS +4 .TP .ie t \(bu .el o The values of \fBshm_perm.cuid\fR, \fBshm_perm.uid\fR, \fBshm_perm.cgid\fR, and \fBshm_perm.gid\fR are set equal to the effective user \fBID\fR and effective group ID, respectively, of the calling process. .RE .RS +4 .TP .ie t \(bu .el o The access permission bits of \fBshm_perm.mode\fR are set equal to the access permission bits of \fIshmflg\fR. \fBshm_segsz\fR is set equal to the value of \fIsize\fR. .RE .RS +4 .TP .ie t \(bu .el o The values of \fBshm_lpid\fR, \fBshm_nattch\fR \fBshm_atime\fR, and \fBshm_dtime\fR are set equal to 0. .RE .RS +4 .TP .ie t \(bu .el o The \fBshm_ctime\fR is set equal to the current time. .RE .sp .LP Shared memory segments must be explicitly removed after the last reference to them has been removed. .sp .LP The \fBshmget_osm()\fR system call is a variant of \fBshmget()\fR which creates an optimized shared memory (OSM) segment. The new fourth argument, granule_size, specifies the segment's granule size. This value must be a power of two which is atleast as large as the value returned by \fBsysconf\fR(\fB_SC_OSM_PAGESIZE_MIN\fR). A segment created with \fBshmget_osm()\fR starts out with all granules unlocked. Unlocked granules have \fBPROT_NONE\fR permissions, and have no memory allocated to back them. The \fBmemcntl\fR(2) \fBMC_LOCK_GRANULE\fR operation can be used to lock granules in a \fBshmget_osm\fR(2) created segment which has been mapped into the address space with \fBshmat\fR(2). .SH RETURN VALUES .sp .LP Upon successful completion, a non-negative integer representing a shared memory identifier is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBshmget()\fR and \fBshmget_osm()\fR functions will fail if: .sp .ne 2 .mk .na \fB\fBEACCES\fR\fR .ad .RS 10n .rt A shared memory identifier exists for \fIkey\fR but operation permission (see \fBIntro\fR(2)) as specified by the low-order 9 bits of \fIshmflg\fR would not be granted. .RE .sp .ne 2 .mk .na \fB\fBEEXIST\fR\fR .ad .RS 10n .rt A shared memory identifier exists for \fIkey\fR but both (\fIshmflg\fR\fB&IPC_CREAT\fR) and (\fIshmflg\fR\fB&IPC_EXCL\fR) are true. .RE .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 10n .rt The \fIsize\fR argument is less than the system-imposed minimum or greater than the system-imposed maximum. See NOTES. .sp For \fBshmget()\fR, a shared memory identifier exists for \fIkey\fR but the size of the segment associated with it is less than \fIsize\fR and \fIsize\fR is not equal to 0. .sp For \fBshmget_osm()\fR, \fIsize\fR and \fIgranule_size\fR are not both zero, and there is an existing segment whose \fIsize\fR and \fIgranule_size\fR do not match the passed in values. .sp For \fBshmget_osm()\fR, either \fIsize\fR or \fIgranule_size\fR are zero, and there is no existing segment. .sp For \fBshmget_osm()\fR, a new segment is going to be created, \fIsize\fR is not a multiple of \fIgranule_size\fR, or \fIgranule_size\fR is not a power-of-2 greater than the value returned by \fBsysconf\fR(\fB_SC_OSM_PAGESIZE_MIN\fR). .RE .sp .ne 2 .mk .na \fB\fBENOENT\fR\fR .ad .RS 10n .rt A shared memory identifier does not exist for \fIkey\fR and (\fIshmflg\fR\fB&IPC_CREAT\fR) is false. .RE .sp .ne 2 .mk .na \fB\fBENOMEM\fR\fR .ad .RS 10n .rt A shared memory identifier and associated shared memory segment are to be created but the amount of available memory is not sufficient to fill the request. .RE .sp .ne 2 .mk .na \fB\fBENOSPC\fR\fR .ad .RS 10n .rt A shared memory identifier is to be created but the system-imposed limit on the maximum number of allowed shared memory identifiers system-wide would be exceeded. See NOTES. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ StandardSee \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBrctladm\fR(1M), \fBIntro\fR(2), \fBsetrctl\fR(2), \fBshmctl\fR(2), \fBshmop\fR(2), \fBftok\fR(3C), \fBgetpagesize\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5) .SH NOTES .sp .LP The \fBproject.max-shm-memory\fR resource control restricts the total amount of shared memory a project can allocate. The \fBzone.max-shm-memory\fR resource control restricts the total amount of shared memory that can be allocated by a zone. The system-imposed maximum on the size of a shared memory segment is therefore a function of the sizes of any other shared memory segments the calling project might have allocated that are still in use, as well as any other shared memory segments allocated and still in use by processes in the zone. For accounting purposes, segment sizes are rounded up to the nearest multiple of the system page size. See \fBgetpagesize\fR(3C). .sp .LP The system-imposed limit on the number of shared memory identifiers is maintained on a per-project basis using the \fBproject.max-shm-ids\fR resource control. The \fBzone.max-shm-ids\fR resource control restricts the total number of shared memory identifiers that can be allocated by a zone. .sp .LP See \fBrctladm\fR(1M) and \fBsetrctl\fR(2) for information about using resource controls.