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
|
|
|
.\"
|
2010-12-17 21:10:08 +00:00
|
|
|
.Dd December 17, 2010
|
1995-10-03 19:17:21 +00:00
|
|
|
.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 sys/types.h
|
|
|
|
.In sys/ipc.h
|
|
|
|
.In sys/shm.h
|
1995-10-03 19:17:21 +00:00
|
|
|
.Ft int
|
2003-01-25 21:33:05 +00:00
|
|
|
.Fn shmget "key_t key" "size_t 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
|
2004-07-02 23:52:20 +00:00
|
|
|
IPC object.
|
|
|
|
There are three ways to specify a key:
|
1995-10-03 19:17:21 +00:00
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
IPC_PRIVATE may be specified, in which case a new IPC object
|
|
|
|
will be created.
|
|
|
|
.It
|
2004-07-02 23:52:20 +00:00
|
|
|
An integer constant may be specified.
|
|
|
|
If no IPC object corresponding
|
1995-10-03 19:17:21 +00:00
|
|
|
to
|
|
|
|
.Fa key
|
|
|
|
is specified and the IPC_CREAT bit is set in
|
|
|
|
.Fa flag ,
|
|
|
|
a new one will be created.
|
|
|
|
.It
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Xr ftok 3
|
|
|
|
may be used to generate a key from a pathname.
|
1995-10-03 19:17:21 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The mode of a newly created IPC object is determined by
|
|
|
|
.Em OR Ns 'ing
|
|
|
|
the following constants into the
|
|
|
|
.Fa flag
|
2002-12-19 09:40:28 +00:00
|
|
|
argument:
|
1995-10-03 19:17:21 +00:00
|
|
|
.Bl -tag -width XSHM_WXX6XXX
|
2010-12-17 21:10:08 +00:00
|
|
|
.It Dv S_IRUSR
|
|
|
|
Read access for owner.
|
|
|
|
.It Dv S_IWUSR
|
|
|
|
Write access for owner.
|
|
|
|
.It Dv S_IRGRP
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for group.
|
2010-12-17 21:10:08 +00:00
|
|
|
.It Dv S_IWGRP
|
1995-10-03 19:17:21 +00:00
|
|
|
Write access for group.
|
2010-12-17 21:10:08 +00:00
|
|
|
.It Dv S_IROTH
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for other.
|
2010-12-17 21:10:08 +00:00
|
|
|
.It Dv S_IWOTH
|
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
|
2004-07-02 23:52:20 +00:00
|
|
|
indicates the desired size of the new segment in bytes.
|
|
|
|
The size
|
1995-10-03 19:17:21 +00:00
|
|
|
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
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Fn shmget
|
|
|
|
system call
|
1995-10-03 19:17:21 +00:00
|
|
|
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 ,
|
2010-12-18 10:09:07 +00:00
|
|
|
.Xr stat 2 ,
|
|
|
|
.Xr ftok 3
|