'\" te .\" Copyright (c) 2006, Sun Microsystems, Inc. All Rights Reserved. .\" Copyright 1989 AT&T .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] .TH SHMGET 2 "Aug 14, 2006" .SH NAME shmget \- 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); .fi .SH DESCRIPTION .sp .LP The \fBshmget()\fR function returns 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. .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 function will fail if: .sp .ne 2 .na \fB\fBEACCES\fR\fR .ad .RS 10n 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 .na \fB\fBEEXIST\fR\fR .ad .RS 10n 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 .na \fB\fBEINVAL\fR\fR .ad .RS 10n The \fIsize\fR argument is less than the system-imposed minimum or greater than the system-imposed maximum. See NOTES. .sp 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. .RE .sp .ne 2 .na \fB\fBENOENT\fR\fR .ad .RS 10n A shared memory identifier does not exist for \fIkey\fR and (\fIshmflg\fR\fB&IPC_CREAT\fR) is false. .RE .sp .ne 2 .na \fB\fBENOMEM\fR\fR .ad .RS 10n 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 .na \fB\fBENOSPC\fR\fR .ad .RS 10n 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(7) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Standard .TE .SH SEE ALSO .sp .LP .BR Intro (2), .BR setrctl (2), .BR shmctl (2), .BR shmop (2), .BR ftok (3C), .BR getpagesize (3C), .BR attributes (7), .BR standards (7), .BR rctladm (8) .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(8) and \fBsetrctl\fR(2) for information about using resource controls.