1995-10-03 19:17:21 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com>
|
|
|
|
.\"
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
1999-08-28 00:22:10 +00:00
|
|
|
.\" $FreeBSD$
|
1995-10-03 19:17:21 +00:00
|
|
|
.\"
|
|
|
|
.Dd July 3, 1995
|
|
|
|
.Dt SHMGET 2
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm shmget
|
|
|
|
.Nd obtain a shared memory identifier
|
2000-04-21 09:42:15 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In machine/param.h
|
|
|
|
.In sys/types.h
|
|
|
|
.In sys/ipc.h
|
|
|
|
.In sys/shm.h
|
1995-10-03 19:17:21 +00:00
|
|
|
.Ft int
|
1997-03-18 23:57:33 +00:00
|
|
|
.Fn shmget "key_t key" "int size" "int flag"
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
Based on the values of
|
|
|
|
.Fa key
|
|
|
|
and
|
|
|
|
.Fa flag ,
|
|
|
|
.Fn shmget
|
|
|
|
returns the identifier of a newly created or previously existing shared
|
|
|
|
memory segment.
|
|
|
|
.\"
|
|
|
|
.\" The following bit about keys and modes also applies to semaphores
|
|
|
|
.\" and message queues.
|
|
|
|
.\"
|
|
|
|
The key
|
|
|
|
is analogous to a filename: it provides a handle that names an
|
|
|
|
IPC object. There are three ways to specify a key:
|
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
IPC_PRIVATE may be specified, in which case a new IPC object
|
|
|
|
will be created.
|
|
|
|
.It
|
|
|
|
An integer constant may be specified. If no IPC object corresponding
|
|
|
|
to
|
|
|
|
.Fa key
|
|
|
|
is specified and the IPC_CREAT bit is set in
|
|
|
|
.Fa flag ,
|
|
|
|
a new one will be created.
|
|
|
|
.It
|
|
|
|
.Fn ftok
|
|
|
|
may be used to generate a key from a pathname. See
|
|
|
|
.Xr ftok 3 .
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The mode of a newly created IPC object is determined by
|
|
|
|
.Em OR Ns 'ing
|
|
|
|
the following constants into the
|
|
|
|
.Fa flag
|
|
|
|
parameter:
|
|
|
|
.Bl -tag -width XSHM_WXX6XXX
|
|
|
|
.It Dv SHM_R
|
|
|
|
Read access for user.
|
|
|
|
.It Dv SHM_W
|
|
|
|
Write access for user.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Dv ( SHM_R>>3 )
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for group.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Dv ( SHM_W>>3 )
|
1995-10-03 19:17:21 +00:00
|
|
|
Write access for group.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Dv ( SHM_R>>6 )
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for other.
|
2001-02-01 16:38:02 +00:00
|
|
|
.It Dv ( SHM_W>>6 )
|
1995-10-03 19:17:21 +00:00
|
|
|
Write access for other.
|
|
|
|
.El
|
|
|
|
.\"
|
|
|
|
.\" XXX - we should also mention how uid, euid, and gid affect ownership
|
|
|
|
.\" and use
|
|
|
|
.\"
|
|
|
|
.\" end section about keys and modes
|
|
|
|
.\"
|
|
|
|
.Pp
|
|
|
|
When creating a new shared memory segment,
|
|
|
|
.Fa size
|
|
|
|
indicates the desired size of the new segment in bytes. The size
|
|
|
|
of the segment may be rounded up to a multiple convenient to the
|
|
|
|
kernel (i.e., the page size).
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
Upon successful completion,
|
|
|
|
.Fn shmget
|
|
|
|
returns the positive integer identifier of a shared memory segment.
|
|
|
|
Otherwise, -1 is returned and
|
|
|
|
.Va errno
|
|
|
|
set to indicate the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
.Fn Shmget
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.\"
|
|
|
|
.\" XXX What about ipcperm failing?
|
|
|
|
.\"
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
Size specified is greater than the size of the previously existing segment.
|
1996-01-30 16:34:52 +00:00
|
|
|
Size specified is less than the system imposed minimum, or greater than
|
1995-10-03 19:17:21 +00:00
|
|
|
the system imposed maximum.
|
|
|
|
.It Bq Er ENOENT
|
|
|
|
No shared memory segment was found matching
|
|
|
|
.Fa key ,
|
|
|
|
and IPC_CREAT was not specified.
|
|
|
|
.It Bq Er ENOSPC
|
|
|
|
The kernel was unable to allocate enough memory to
|
|
|
|
satisfy the request.
|
|
|
|
.It Bq Er EEXIST
|
|
|
|
IPC_CREAT and IPC_EXCL were specified, and a shared memory segment
|
|
|
|
corresponding to
|
|
|
|
.Fa key
|
|
|
|
already exists.
|
2000-12-29 14:08:20 +00:00
|
|
|
.El
|
2001-07-15 07:53:42 +00:00
|
|
|
.Sh "SEE ALSO"
|
1995-10-03 19:17:21 +00:00
|
|
|
.Xr shmat 2 ,
|
1997-01-20 23:23:22 +00:00
|
|
|
.Xr shmctl 2 ,
|
1995-10-03 19:17:21 +00:00
|
|
|
.Xr shmdt 2 ,
|
|
|
|
.Xr ftok 3
|