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
|
|
|
.\"
|
2018-03-04 20:06:02 +00:00
|
|
|
.Dd March 4, 2018
|
1995-10-03 19:17:21 +00:00
|
|
|
.Dt SEMGET 2
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm semget
|
|
|
|
.Nd obtain a semaphore id
|
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/sem.h
|
1995-10-03 19:17:21 +00:00
|
|
|
.Ft int
|
1997-03-18 23:57:33 +00:00
|
|
|
.Fn semget "key_t key" "int nsems" "int flag"
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
Based on the values of
|
|
|
|
.Fa key
|
|
|
|
and
|
|
|
|
.Fa flag ,
|
|
|
|
.Fn semget
|
|
|
|
returns the identifier of a newly created or previously existing
|
|
|
|
set of semaphores.
|
|
|
|
.\"
|
|
|
|
.\" This is copied verbatim from the shmget manpage. Perhaps
|
|
|
|
.\" it should go in a common manpage, such as .Xr ipc 2
|
|
|
|
.\"
|
|
|
|
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
|
|
|
|
function
|
|
|
|
may be used to generate a key from a pathname.
|
1995-10-03 19:17:21 +00:00
|
|
|
.El
|
|
|
|
.\"
|
|
|
|
.\" Likewise for this section, except SHM_* becomes SEM_*.
|
|
|
|
.\"
|
|
|
|
.Pp
|
2018-03-04 20:06:02 +00:00
|
|
|
The mode of a newly created IPC object is determined by ORing these constants
|
|
|
|
into the
|
1995-10-03 19:17:21 +00:00
|
|
|
.Fa flag
|
2002-12-19 09:40:28 +00:00
|
|
|
argument:
|
2018-03-04 20:06:02 +00:00
|
|
|
.Bl -tag -width 0000
|
|
|
|
.It Dv 0400
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for user.
|
2018-03-04 20:06:02 +00:00
|
|
|
.It Dv 0200
|
1996-12-03 23:03:22 +00:00
|
|
|
Alter access for user.
|
2018-03-04 20:06:02 +00:00
|
|
|
.It Dv 0040
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for group.
|
2018-03-04 20:06:02 +00:00
|
|
|
.It Dv 0020
|
1996-12-03 23:03:22 +00:00
|
|
|
Alter access for group.
|
2018-03-04 20:06:02 +00:00
|
|
|
.It Dv 0004
|
1995-10-03 19:17:21 +00:00
|
|
|
Read access for other.
|
2018-03-04 20:06:02 +00:00
|
|
|
.It Dv 0002
|
1996-12-03 23:03:22 +00:00
|
|
|
Alter access for other.
|
1995-10-03 19:17:21 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
If a new set of semaphores is being created,
|
|
|
|
.Fa nsems
|
|
|
|
is used to indicate the number of semaphores the set should contain.
|
|
|
|
Otherwise,
|
|
|
|
.Fa nsems
|
|
|
|
may be specified as 0.
|
|
|
|
.Sh RETURN VALUES
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Fn semget
|
|
|
|
system call
|
1995-10-03 19:17:21 +00:00
|
|
|
returns the id of a semaphore set if successful; otherwise, -1
|
|
|
|
is returned and
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Fn semget
|
|
|
|
system call
|
1995-10-03 19:17:21 +00:00
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
2005-02-15 09:27:00 +00:00
|
|
|
.\" ipcperm could fail (we are opening to read and write, as it were)
|
1995-10-03 19:17:21 +00:00
|
|
|
.It Bq Er EACCES
|
|
|
|
Access permission failure.
|
|
|
|
.\"
|
|
|
|
.\" sysv_sem.c is quite explicit about these, so I'm pretty sure
|
|
|
|
.\" this is accurate
|
|
|
|
.\"
|
|
|
|
.It Bq Er EEXIST
|
|
|
|
IPC_CREAT and IPC_EXCL were specified, and a semaphore set
|
|
|
|
corresponding to
|
|
|
|
.Fa key
|
|
|
|
already exists.
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
The number of semaphores requested exceeds the system imposed maximum
|
|
|
|
per set.
|
2016-02-07 21:25:08 +00:00
|
|
|
.It Bq Er EINVAL
|
|
|
|
A semaphore set corresponding to
|
|
|
|
.Fa key
|
|
|
|
already exists and contains fewer semaphores than
|
|
|
|
.Fa nsems .
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
A semaphore set corresponding to
|
|
|
|
.Fa key
|
|
|
|
does not exist and
|
|
|
|
.Fa nsems
|
|
|
|
is 0 or negative.
|
1995-10-03 19:17:21 +00:00
|
|
|
.It Bq Er ENOSPC
|
|
|
|
Insufficiently many semaphores are available.
|
|
|
|
.It Bq Er ENOSPC
|
|
|
|
The kernel could not allocate a
|
|
|
|
.Fa "struct semid_ds" .
|
|
|
|
.It Bq Er ENOENT
|
|
|
|
No semaphore set was found corresponding to
|
|
|
|
.Fa key ,
|
|
|
|
and IPC_CREAT was not specified.
|
2000-12-29 14:08:20 +00:00
|
|
|
.El
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr semctl 2 ,
|
1998-01-02 19:22:52 +00:00
|
|
|
.Xr semop 2 ,
|
|
|
|
.Xr ftok 3
|