p The f -literal semid_ds .Ef structure used in the .Dv IPC_SET and .Dv IPC_STAT commands is defined as follows in .Aq Pa sys/sem.h : d -literal struct semid_ds { struct ipc_perm sem_perm; /* operation permissions */ struct sem *sem_base; /* semaphore set */ u_short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ }; .Ed
p The f -literal ipc_perm .Ef structure used inside the f -literal semid_ds .Ef structure is defined in .Aq Pa sys/ipc.h and looks like this: d -literal struct ipc_perm { ushort cuid; /* creator user id */ ushort cgid; /* creator group id */ ushort uid; /* user id */ ushort gid; /* group id */ ushort mode; /* r/w permission (see chmod(2)) */ ushort seq; /* sequence # (to generate unique msg/sem/shm id) */ key_t key; /* user specified msg/sem/shm key */ }; .Ed
p .Fn semctl provides the following operations: l -tag -width IPC_RMIDX t Dv GETVAL Return the value of the semaphore. t Dv SETVAL Set the value of the semaphore to .Fa arg.val . t Dv GETPID Return the pid of the last process that did an operation on this semaphore. t Dv GETNCNT Return the number of processes waiting to acquire the semaphore. t Dv GETZCNT Return the number of processes waiting for the value of the semaphore to reach 0. t Dv GETALL Return the values of all the semaphores associated with .Fa semid . t Dv SETALL Set the values of all the semaphores that are associated with the semaphore identifier .Fa semid to the corresponding values in .Fa arg.array . t Dv IPC_STAT Gather statistics about a semaphore and place the information in the f -literal semid_ds .Ef structure pointed to by .Fa arg.buf (see above). t Dv IPC_SET Set the value of the .Va sem_perm.uid , .Va sem_perm.gid and .Va sem_perm.mode fields in the structure associated with the semaphore. The values are taken from the corresponding fields in the structure pointed to by .Fa arg.buf . This operation can only be executed by the super-user, or a process that has an effective user id equal to either .Va sem_perm.cuid or .Va sem_perm.uid in the data structure associated with the message queue. t Dv IPC_RMID Remove the semaphores associated with .Fa semid from the system and destroy the data structures associated with it. Only the super-user or a process with an effective uid equal to the .Va sem_perm.cuid or .Va sem_perm.uid values in the data structure associated with the semaphore can do this. .El
p The permission to read or change a message queue (see .Xr semop 2 ) is determined by the .Va sem_perm.mode field in the same way as is done with files (see .Xr chmod 2 ), but the effective uid can match either the .Va sem_perm.cuid field or the .Va sem_perm.uid field, and the effective gid can match either .Va sem_perm.cgid or .Va sem_perm.gid . .Sh RETURN VALUES For the .Dv GETVAL , .Dv GETPID , .Dv GETNCNT , and .Dv GETZCNT operations, .Fn semctl returns one of the values described above if successful. All other operations will make .Fn semctl return 0 if no errors occur. Otherwise -1 is returned and .Va errno set to reflect the error. .Sh ERRORS .Fn semctl will fail if: l -tag -width Er t Bq Er EPERM .Fa cmd is equal to .Dv IPC_SET or .Dv IPC_RMID and the caller is not the super-user, nor does the effective uid match either the .Va sem_perm.uid or .Va sem_perm.cuid fields of the data structure associated with the message queue. t Bq Er EACCES The caller has no operation permission for this semaphore. t Bq Er EINVAL .Fa semid is not a valid message semaphore identifier.
p .Va cmd is not a valid command. t Bq Er EFAULT .Fa arg.buf specifies an invalid address. .El .Sh SEE ALSO .Xr semget 2 , .Xr semop 2