semctl(2)
_________________________________________________________________
semctl System Call
Semaphore control operations.
_________________________________________________________________
SYNTAX
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semctl (id, semnum, command, arg)
int id;
int semnum;
int command;
union semun * arg;
PARAMETERS
id A semaphore set identifier.
semnum The subject semaphore. Used only if <command> is
GETVAL, SETVAL, GETNCNT, GETZCNT or GETPID.
command The semaphore operation to be performed.
arg An argument. Used only if <command> is SETVAL,
GETALL, SETALL, IPC_STAT, OR IPC_SET.
DESCRIPTION
Semctl provides semaphore control operations as specified by
<command>. The subject semaphore set is identified by <id>. The
action taken depends on the value of <command> as follows:
SETVAL
Set the value of semaphore number <semnum> to <arg.val>.
When this <command> is successfully executed, all processes
having a semaphore adjustment value corresponding to semaphore
number <semnum> will have those values set to zero.
If an error occurs, the semaphore set is unchanged.
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
semctl(2)
GETVAL
Return the value of semaphore number <semnum>.
GETPID
Return the process id of the last process to perform an
operation on semaphore number <semnum>.
GETNCNT
Return the number of processes waiting for the value of
semaphore number <semnum> to increase.
GETZCNT
Return the number of processes waiting for the value of
semaphore number <semnum> to become zero.
SETALL
Set the value of all semaphores in the specified semaphore
set to the values contained in the array pointed to by
<arg.array>.
When this <command> is successfully executed, all processes
having a semaphore adjustment value corresponding to a semaphore
in the specified semaphore set will have those values set to
zero.
If an error occurs, the semaphore set is unchanged.
GETALL
Return the value of all semaphores in the specified
semaphore set using the array pointed to by <arg.array>.
If an error occurs, the contents of <arg.array> are undefined.
IPC_STAT
The current semaphore set attributes are stored in the
structure pointed to by <arg.buf>.
If an error occurs, the contents of <arg.buf> are undefined.
IPC_SET
The following semaphore set attributes are set to the values
found in the structure pointed to by <arg.buf>: user id
(sem_perm.uid), group id (sem_perm.gid), and permission
rights (in sem_perm.mode).
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
semctl(2)
If an error occurs, the semaphore set remains unchanged.
Otherwise, the last change time (sem_ctime) is set to the current
time.
IPC_RMID
The semaphore set is destroyed. All resources consumed by
the semaphore set are freed and the semaphore set identifier
is invalidated.
If an error occurs, the semaphore set remains unchanged.
ACCESS CONTROL
Operation permission depends on the value of <command> as
follows:
* If <command> is GETVAL, GETPID, GETNCNT, GETZCNT, GETALL, or
IPC_STAT, the calling process is required to have read
access to the semaphore set.
* If <command> is SETVAL or SETALL, the calling process is
required to have alter access to the semaphore set.
* If <command> is IPC_SET or IPC_RMID, the effective user id
of the calling process must be equal to the semaphore set's
user id (sem_perm.uid), the semaphore set creator's user id
(sem_perm.cuid), or that of the superuser.
RETURN VALUE
The value returned may be the following regardless of the value
of <command>:
-1 An error occurred. Errno is set to indicate the
error.
If <command> is GETVAL, the value returned may be the following:
<semaphore_value>
Completed successfully. The specified semaphore's
value is returned.
If <command> is GETPID, the value returned may be the following:
<process_id> Completed successfully. The process id of the
last process to perform an operation on the
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)
semctl(2)
specified semaphore is returned.
If <command> is GETNCNT, the value returned may be the following:
<process_id_count>
Completed successfully. The number of processes
waiting for the value of the specified semaphore
to increase is returned.
If <command> is GETZCNT, the value returned may be the following:
<process_id_count>
Completed successfully. The number of processes
waiting for the value of the specified semaphore
to become zero is returned.
If <command> is SETVAL, GETALL, SETALL, IPC_STAT, IPC_SET, or
IPC_RMID, the value returned may be the following:
0 Completed successfully.
EXCEPTIONS
Errno may be set to one of the following error codes regardless
of the value of <command>:
EINVAL <id> is not a valid semaphore set identifier.
EINVAL <command> is invalid.
If <command> is GETVAL, GETPID, GETNCNT, or GETZCNT, errno may be
set to one of these values:
EINVAL <semnum> is less than zero or greater than the
number of semaphores in the semaphore set
identified by <id>.
EACCES Read permission is denied to the calling process.
If <command> is SETVAL, errno may be set to one of the following:
EINVAL <Semaphore> is less than zero or greater than the
DG/UX 4.00 Page 4
Licensed material--property of copyright holder(s)
semctl(2)
number of semaphores in the semaphore set
identified by <id>.
EACCES Alter permission is denied to the calling process.
ERANGE The value to which the selected semaphore is to be
set, <arg.val>, is greater than the system-imposed
maximum.
If <command> is GETALL, errno may be set to one of these values:
EACCES Read permission is denied to the calling process.
EFAULT <Argument.array> points to an illegal address.
If <command> is SETALL, errno may be set to one of these values:
EACCES Alter permission is denied to the calling process.
ERANGE The value to which one of the semaphores is to be
set is greater than the system-imposed maximum.
EFAULT <Argument.array> points to an illegal address.
If <command> is IPC_STAT, errno may be set to one of these
values:
EACCES Read permission is denied to the calling process.
EFAULT <Argument.buf> points to an illegal address.
If <command> is IPC_SET, errno may be set to one of these values:
EPERM Permission to change the semaphore set attributes
is denied to the calling process.
EFAULT <Argument.buf> points to an illegal address.
If <command> is IPC_RMID, errno may be set to this value:
DG/UX 4.00 Page 5
Licensed material--property of copyright holder(s)
semctl(2)
EPERM Permission to remove the semaphore set is denied
to the calling process.
SEE ALSO
The related system calls: semget, semop.
The related manual section: intro(2).
DG/UX 4.00 Page 6
Licensed material--property of copyright holder(s)