sem_getvalue Subroutine

Purpose

Gets the value of a semaphore.

Library

Standard C Library (libc.a)

Syntax

#include <semaphore.h>

int sem_getvalue (sem, sval)
sem_t *restrict sem;
int *restrict sval;

Description

The sem_getvalue subroutine updates the location referenced by the sval parameter to have the value of the semaphore referenced by the sem parameter without affecting the state of the semaphore. The updated value represents an actual semaphore value that occurred at some unspecified time during the call, but it need not be the actual value of the semaphore when it is returned to the calling process.

If the sem parameter is locked, the object to which the sval parameter points is set to a negative number whose absolute value represents the number of processes waiting for the semaphore at an unspecified time during the call.

Parameters

Item Description
sem Indicates the semaphore to be retrieved.
sval Specifies the location where the semaphore value is stored.

Return Values

Upon successful completion, the sem_getvalue subroutine returns a 0. Otherwise, it returns a -1 and sets errno to indicate the error.

Error Codes

The sem_getvalue subroutine fails if:
Item Description
EACCES Permission is denied to access the unnamed semaphore.
EFAULT Invalid user address.
EINVAL The sem parameter does not refer to a valid semaphore.
ENOMEM Insufficient memory for the required operation.
ENOTSUP This function is not supported with processes that have been checkpoint-restart'ed.