.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
.TH "SHMGET" 3P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" shmget
.SH PROLOG
This manual page is part of the POSIX Programmer's Manual.
The Linux implementation of this interface may differ (consult
the corresponding Linux manual page for details of Linux behavior),
or the interface may not be implemented on Linux.
.SH NAME
shmget \- get an XSI shared memory segment
.SH SYNOPSIS
.LP
\fB#include <sys/shm.h>
.br
.sp
int shmget(key_t\fP \fIkey\fP\fB, size_t\fP \fIsize\fP\fB, int\fP
\fIshmflg\fP\fB); \fP
\fB
.br
\fP
.SH DESCRIPTION
.LP
The \fIshmget\fP() function operates on XSI shared memory (see the
Base Definitions volume of IEEE\ Std\ 1003.1-2001,
Section 3.340, Shared Memory Object). It is unspecified whether this
function
interoperates with the realtime interprocess communication facilities
defined in \fIRealtime\fP .
.LP
The \fIshmget\fP() function shall return the shared memory identifier
associated with \fIkey\fP.
.LP
A shared memory identifier, associated data structure, and shared
memory segment of at least \fIsize\fP bytes (see \fI<sys/shm.h>\fP)
are created for \fIkey\fP if one of the following is true:
.IP " *" 3
The argument \fIkey\fP is equal to IPC_PRIVATE.
.LP
.IP " *" 3
The argument \fIkey\fP does not already have a shared memory identifier
associated with it and (\fIshmflg\fP &IPC_CREAT)
is non-zero.
.LP
.LP
Upon creation, the data structure associated with the new shared memory
identifier shall be initialized as follows:
.IP " *" 3
The values of \fIshm_perm.cuid\fP, \fIshm_perm.uid\fP, \fIshm_perm.cgid\fP,
and \fIshm_perm.gid\fP are set equal to the
effective user ID and effective group ID, respectively, of the calling
process.
.LP
.IP " *" 3
The low-order nine bits of \fIshm_perm.mode\fP are set equal to the
low-order nine bits of \fIshmflg\fP.
.LP
.IP " *" 3
The value of \fIshm_segsz\fP is set equal to the value of \fIsize\fP.
.LP
.IP " *" 3
The values of \fIshm_lpid\fP, \fIshm_nattch\fP, \fIshm_atime\fP, and
\fIshm_dtime\fP are set equal to 0.
.LP
.IP " *" 3
The value of \fIshm_ctime\fP is set equal to the current time.
.LP
.LP
When the shared memory segment is created, it shall be initialized
with all zero values.
.SH RETURN VALUE
.LP
Upon successful completion, \fIshmget\fP() shall return a non-negative
integer, namely a shared memory identifier; otherwise,
it shall return -1 and set \fIerrno\fP to indicate the error.
.SH ERRORS
.LP
The \fIshmget\fP() function shall fail if:
.TP 7
.B EACCES
A shared memory identifier exists for \fIkey\fP but operation permission
as specified by the low-order nine bits of
\fIshmflg\fP would not be granted; see \fIXSI Interprocess Communication\fP
\&.
.TP 7
.B EEXIST
A shared memory identifier exists for the argument \fIkey\fP but (\fIshmflg\fP
&IPC_CREAT) &&(\fIshmflg\fP
&IPC_EXCL) is non-zero.
.TP 7
.B EINVAL
A shared memory segment is to be created and the value of size is
less than the system-imposed minimum or greater than the
system-imposed maximum.
.TP 7
.B EINVAL
No shared memory segment is to be created and a shared memory segment
exists for \fIkey\fP but the size of the segment
associated with it is less than \fIsize\fP and \fIsize\fP is not 0.
.TP 7
.B ENOENT
A shared memory identifier does not exist for the argument \fIkey\fP
and (\fIshmflg\fP &IPC_CREAT) is 0.
.TP 7
.B ENOMEM
A shared memory identifier and associated shared memory segment shall
be created, but the amount of available physical memory
is not sufficient to fill the request.
.TP 7
.B ENOSPC
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.
.sp
.LP
\fIThe following sections are informative.\fP
.SH EXAMPLES
.LP
None.
.SH APPLICATION USAGE
.LP
The POSIX Realtime Extension defines alternative interfaces for interprocess
communication. Application developers who need to
use IPC should design their applications so that modules using the
IPC routines described in \fIXSI Interprocess Communication\fP can
be easily modified to use the alternative
interfaces.
.SH RATIONALE
.LP
None.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIXSI Interprocess Communication\fP, \fIRealtime\fP, \fIshmat\fP(),
\fIshmctl\fP(), \fIshmdt\fP(), \fIshm_open\fP(), \fIshm_unlink\fP(),
the Base Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<sys/shm.h>\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .
|