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 September 12, 1995
|
|
|
|
.Dt SEMCTL 2
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm semctl
|
|
|
|
.Nd control operations on a semaphore set
|
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/sem.h
|
1995-10-03 19:17:21 +00:00
|
|
|
.Ft int
|
1998-09-12 01:27:34 +00:00
|
|
|
.Fn semctl "int semid" "int semnum" "int cmd" ...
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Fn semctl
|
|
|
|
system call
|
1995-10-03 19:17:21 +00:00
|
|
|
performs the operation indicated by
|
|
|
|
.Fa cmd
|
|
|
|
on the semaphore set indicated by
|
|
|
|
.Fa semid .
|
1998-09-12 01:27:34 +00:00
|
|
|
A fourth argument, a
|
|
|
|
.Fa "union semun arg" ,
|
2001-07-15 07:53:42 +00:00
|
|
|
is required for certain values of
|
1998-09-12 01:27:34 +00:00
|
|
|
.Fa cmd .
|
1995-10-03 19:17:21 +00:00
|
|
|
For the commands that use the
|
|
|
|
.Fa arg
|
2002-12-19 09:40:28 +00:00
|
|
|
argument,
|
1995-10-03 19:17:21 +00:00
|
|
|
.Fa "union semun"
|
|
|
|
is defined as follows:
|
|
|
|
.Bd -literal
|
|
|
|
.\"
|
|
|
|
.\" From <sys/sem.h>:
|
|
|
|
.\"
|
|
|
|
union semun {
|
|
|
|
int val; /* value for SETVAL */
|
|
|
|
struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
|
|
|
|
u_short *array; /* array for GETALL & SETALL */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Commands are performed as follows:
|
|
|
|
.\"
|
|
|
|
.\" This section based on Stevens, _Advanced Programming in the UNIX
|
|
|
|
.\" Environment_.
|
|
|
|
.\"
|
|
|
|
.Bl -tag -width IPC_RMIDXXX
|
|
|
|
.It Dv IPC_STAT
|
|
|
|
Fetch the semaphore set's
|
|
|
|
.Fa "struct semid_ds" ,
|
|
|
|
storing it in the memory pointed to by
|
|
|
|
.Fa arg.buf .
|
|
|
|
.It Dv IPC_SET
|
|
|
|
Changes the
|
|
|
|
.Fa sem_perm.uid ,
|
|
|
|
.Fa sem_perm.gid ,
|
|
|
|
and
|
|
|
|
.Fa sem_perm.mode
|
|
|
|
members of the semaphore set's
|
|
|
|
.Fa "struct semid_ds"
|
|
|
|
to match those of the struct pointed to by
|
|
|
|
.Fa arg.buf .
|
|
|
|
The calling process's effective uid must
|
|
|
|
match either
|
|
|
|
.Fa sem_perm.uid
|
|
|
|
or
|
|
|
|
.Fa sem_perm.cuid ,
|
|
|
|
or it must have superuser privileges.
|
|
|
|
.It IPC_RMID
|
|
|
|
Immediately removes the semaphore set from the system. The calling
|
1996-01-30 16:34:52 +00:00
|
|
|
process's effective uid must equal the semaphore set's
|
1995-10-03 19:17:21 +00:00
|
|
|
.Fa sem_perm.uid
|
|
|
|
or
|
|
|
|
.Fa sem_perm.cuid ,
|
1996-01-30 16:34:52 +00:00
|
|
|
or the process must have superuser privileges.
|
1995-10-03 19:17:21 +00:00
|
|
|
.It Dv GETVAL
|
|
|
|
Return the value of semaphore number
|
|
|
|
.Fa semnum .
|
|
|
|
.It Dv SETVAL
|
|
|
|
Set the value of semaphore number
|
|
|
|
.Fa semnum
|
|
|
|
to
|
|
|
|
.Fa arg.val .
|
2001-10-11 08:15:14 +00:00
|
|
|
Outstanding adjust on exit values for this semaphore in any process
|
|
|
|
are cleared.
|
1995-10-03 19:17:21 +00:00
|
|
|
.It Dv GETPID
|
|
|
|
Return the pid of the last process to perform an operation on
|
|
|
|
semaphore number
|
|
|
|
.Fa semnum .
|
|
|
|
.It Dv GETNCNT
|
|
|
|
Return the number of processes waiting for semaphore number
|
|
|
|
.Fa semnum Ns 's
|
|
|
|
value to become greater than its current value.
|
|
|
|
.It Dv GETZCNT
|
|
|
|
Return the number of processes waiting for semaphore number
|
|
|
|
.Fa semnum Ns 's
|
|
|
|
value to become 0.
|
|
|
|
.It Dv GETALL
|
|
|
|
Fetch the value of all of the semaphores in the set into the
|
|
|
|
array pointed to by
|
|
|
|
.Fa arg.array .
|
|
|
|
.It Dv SETALL
|
|
|
|
Set the values of all of the semaphores in the set to the values
|
|
|
|
in the array pointed to by
|
|
|
|
.Fa arg.array .
|
2001-10-11 08:15:14 +00:00
|
|
|
Outstanding adjust on exit values for all semaphores in this set,
|
|
|
|
in any process are cleared.
|
1995-10-03 19:17:21 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
2002-12-19 09:40:28 +00:00
|
|
|
.Vt "struct semid_ds"
|
1995-10-03 19:17:21 +00:00
|
|
|
is defined as follows:
|
|
|
|
.Bd -literal
|
|
|
|
.\"
|
|
|
|
.\" Taken straight from <sys/sem.h>.
|
|
|
|
.\"
|
|
|
|
struct semid_ds {
|
|
|
|
struct ipc_perm sem_perm; /* operation permission struct */
|
|
|
|
struct sem *sem_base; /* pointer to first semaphore in set */
|
|
|
|
u_short sem_nsems; /* number of sems in set */
|
|
|
|
time_t sem_otime; /* last operation time */
|
|
|
|
long sem_pad1; /* SVABI/386 says I need this here */
|
|
|
|
time_t sem_ctime; /* last change time */
|
|
|
|
/* Times measured in secs since */
|
|
|
|
/* 00:00:00 GMT, Jan. 1, 1970 */
|
|
|
|
long sem_pad2; /* SVABI/386 says I need this here */
|
|
|
|
long sem_pad3[4]; /* SVABI/386 says I need this here */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
On success, when
|
|
|
|
.Fa cmd
|
2001-10-11 08:15:14 +00:00
|
|
|
is one of
|
2002-03-06 14:14:36 +00:00
|
|
|
.Dv GETVAL , GETPID , GETNCNT
|
2001-10-11 08:15:14 +00:00
|
|
|
or
|
|
|
|
.Dv GETZCNT ,
|
1995-10-03 19:17:21 +00:00
|
|
|
.Fn semctl
|
|
|
|
returns the corresponding value; otherwise, 0 is returned.
|
|
|
|
On failure, -1 is returned, and
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
2002-12-18 09:22:32 +00:00
|
|
|
The
|
|
|
|
.Fn semctl
|
|
|
|
system call
|
1995-10-03 19:17:21 +00:00
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
No semaphore set corresponds to
|
|
|
|
.Fa semid .
|
|
|
|
.It Bq Er EINVAL
|
2002-12-19 09:40:28 +00:00
|
|
|
The
|
1995-10-03 19:17:21 +00:00
|
|
|
.Fa semnum
|
2002-12-19 09:40:28 +00:00
|
|
|
argument
|
1995-10-03 19:17:21 +00:00
|
|
|
is not in the range of valid semaphores for given semaphore set.
|
|
|
|
.It Bq Er EPERM
|
|
|
|
The calling process's effective uid does not match the uid of
|
|
|
|
the semaphore set's owner or creator.
|
|
|
|
.It Bq Er EACCES
|
|
|
|
Permission denied due to mismatch between operation and mode of
|
|
|
|
semaphore set.
|
2001-10-11 08:15:14 +00:00
|
|
|
.It Bq Er ERANGE
|
|
|
|
.Dv SETVAL
|
|
|
|
or
|
|
|
|
.Dv SETALL
|
|
|
|
attempted to set a semaphore outside the allowable range
|
|
|
|
.Bq 0 .. Dv SEMVMX .
|
2000-12-29 14:08:20 +00:00
|
|
|
.El
|
1995-10-03 19:17:21 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr semget 2 ,
|
|
|
|
.Xr semop 2
|
2001-10-11 08:15:14 +00:00
|
|
|
.Sh BUGS
|
|
|
|
.Dv SETALL
|
|
|
|
may update some semaphore elements before returning an error.
|