2003-01-18 13:52:16 +03:00
|
|
|
.\" $NetBSD: semget.2,v 1.14 2003/01/18 11:33:12 thorpej Exp $
|
1995-10-17 02:49:07 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1995 Frank van der Linden
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed for the NetBSD Project
|
|
|
|
.\" by Frank van der Linden
|
|
|
|
.\" 4. The name of the author may not be used to endorse or promote products
|
|
|
|
.\" derived from this software without specific prior written permission
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
1997-11-27 13:24:44 +03:00
|
|
|
.\"
|
1999-08-26 00:55:35 +04:00
|
|
|
.Dd August 25, 1999
|
1995-10-17 02:49:07 +03:00
|
|
|
.Dt SEMGET 2
|
1999-03-22 22:44:33 +03:00
|
|
|
.Os
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm semget
|
1999-08-26 00:55:35 +04:00
|
|
|
.Nd get set of semaphores
|
1999-12-03 00:42:35 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh SYNOPSIS
|
2002-02-08 04:21:55 +03:00
|
|
|
.Fd #include \*[Lt]sys/sem.h\*[Gt]
|
1995-10-17 02:49:07 +03:00
|
|
|
.Ft int
|
|
|
|
.Fn semget "key_t key" "int nsems" "int semflg"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn semget
|
|
|
|
system call returns the semaphore identifier associated with
|
|
|
|
.Fa key .
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
A new set containing
|
|
|
|
.Fa nsems
|
2001-09-16 05:38:59 +04:00
|
|
|
semaphores is created if either
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa key
|
1997-11-27 13:24:44 +03:00
|
|
|
is equal to
|
|
|
|
.Dv IPC_PRIVATE ,
|
|
|
|
or
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa key
|
1997-11-27 13:24:44 +03:00
|
|
|
does not have a semaphore set associated with it and the
|
|
|
|
.Dv IPC_CREAT
|
|
|
|
bit is set in
|
2001-09-16 06:13:26 +04:00
|
|
|
.Fa semflg .
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
If a new set of semaphores is created, the data structure associated with it
|
|
|
|
(the
|
|
|
|
.Va semid_ds
|
|
|
|
structure, see
|
|
|
|
.Xr semctl 2 )
|
1997-11-27 13:24:44 +03:00
|
|
|
is initialized as follows:
|
1995-10-17 02:49:07 +03:00
|
|
|
.Bl -bullet
|
2001-09-16 05:38:59 +04:00
|
|
|
.It
|
1995-10-17 02:49:07 +03:00
|
|
|
.Va sem_perm.cuid
|
|
|
|
and
|
|
|
|
.Va sem_perm.uid
|
|
|
|
are set to the effective uid of the calling process.
|
|
|
|
.It
|
|
|
|
.Va sem_perm.gid
|
|
|
|
and
|
|
|
|
.Va sem_perm.cgid
|
|
|
|
are set to the effective gid of the calling process.
|
|
|
|
.It
|
|
|
|
.Va sem_perm.mode
|
|
|
|
is set to the lower 9 bits of
|
1999-03-06 14:56:53 +03:00
|
|
|
.Fa semflg .
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
|
|
|
.Va sem_nsems
|
|
|
|
is set to the value of
|
1997-11-27 13:24:44 +03:00
|
|
|
.Fa nsems .
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
|
|
|
.Va sem_ctime
|
1997-11-27 13:24:44 +03:00
|
|
|
is set to the current time.
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
|
|
|
.Va sem_otime
|
1997-11-27 13:24:44 +03:00
|
|
|
is set to 0.
|
1995-10-17 02:49:07 +03:00
|
|
|
.El
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
.Fn semget
|
2002-10-01 22:10:43 +04:00
|
|
|
returns a non-negative semaphore identifier if successful.
|
|
|
|
Otherwise, -1 is returned and
|
1995-10-17 02:49:07 +03:00
|
|
|
.Va errno
|
|
|
|
is set to reflect the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
.Bl -tag -width Er
|
1997-11-27 10:36:24 +03:00
|
|
|
.It Bq Er EACCES
|
1995-10-17 02:49:07 +03:00
|
|
|
The caller has no permission to access a semaphore set already associated with
|
2001-09-16 06:13:26 +04:00
|
|
|
.Fa key .
|
1995-10-17 02:49:07 +03:00
|
|
|
.It Bq Er EEXIST
|
1997-11-27 13:24:44 +03:00
|
|
|
Both
|
|
|
|
.Dv IPC_CREAT
|
|
|
|
and
|
|
|
|
.Dv IPC_EXCL
|
|
|
|
are set in
|
1999-03-06 14:56:53 +03:00
|
|
|
.Fa semflg ,
|
1995-10-17 02:49:07 +03:00
|
|
|
and a semaphore set is already associated with
|
|
|
|
.Fa key .
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
.Va nsems
|
|
|
|
is less than 0 or greater than the system limit for the number in a semaphore
|
|
|
|
set.
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
A semaphore set associated with
|
|
|
|
.Fa key
|
|
|
|
exists, but has fewer semaphores than the number specified in
|
|
|
|
.Fa nsems .
|
|
|
|
.It Bq Er ENOSPC
|
|
|
|
A new set of semaphores could not be created because the system limit
|
|
|
|
for the number of semaphores or the number of semaphore sets has been
|
|
|
|
reached.
|
|
|
|
.It Bq Er ENOENT
|
1997-11-27 13:24:44 +03:00
|
|
|
.Dv IPC_CREAT
|
|
|
|
is not set in
|
1999-03-06 14:56:53 +03:00
|
|
|
.Fa semflg
|
1995-10-17 02:49:07 +03:00
|
|
|
and no semaphore set associated with
|
|
|
|
.Fa key
|
|
|
|
was found.
|
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
1997-03-27 11:20:35 +03:00
|
|
|
.Xr semctl 2 ,
|
2001-09-16 06:13:26 +04:00
|
|
|
.Xr semop 2 ,
|
|
|
|
.Xr ftok 3
|
1999-08-26 00:55:35 +04:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
system call conforms to
|
|
|
|
.St -xsh5 .
|
|
|
|
.Sh HISTORY
|
|
|
|
Semaphores appeared in the first release of
|
|
|
|
.At V .
|