CINXE.COM
sem_getvalue
<html> <head> <title>sem_getvalue</title> <META NAME="KEYWORDS" CONTENT="sem_getvalue"> </head> <body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#0000ff" ALINK="#0000ff" TEXT="#000000"> <center> <h1><b>sem_getvalue</b></h1></center> <PRE> <STRONG><A HREF="/man3/SEM_GETVALUE">SEM_GETVALUE(3)</A></STRONG> Linux Programmer's Manual <STRONG><A HREF="/man3/SEM_GETVALUE">SEM_GETVALUE(3)</A></STRONG> NAME sem_getvalue - get the value of a semaphore SYNOPSIS #include <semaphore.h> int sem_getvalue(sem_t *sem, int *sval); Link with -pthread. DESCRIPTION sem_getvalue() places the current value of the semaphore pointed to sem into the integer pointed to by sval. If one or more processes or threads are blocked waiting to lock the semaphore with <STRONG><A HREF="/man3/sem_wait">sem_wait(3)</A></STRONG>, POSIX.1 permits two possibilities for the value returned in sval: either 0 is returned; or a negative number whose absolute value is the count of the number of processes and threads currently blocked in <STRONG><A HREF="/man3/sem_wait">sem_wait(3)</A></STRONG>. Linux adopts the former be- havior. RETURN VALUE sem_getvalue() returns 0 on success; on error, -1 is returned and errno is set to indicate the error. ERRORS EINVAL sem is not a valid semaphore. ATTRIBUTES For an explanation of the terms used in this section, see at- <STRONG><A HREF="/man7/tributes">tributes(7)</A></STRONG>. +---------------+---------------+---------+ |Interface | Attribute | Value | +---------------+---------------+---------+ |sem_getvalue() | Thread safety | MT-Safe | +---------------+---------------+---------+ CONFORMING TO POSIX.1-2001, POSIX.1-2008. NOTES The value of the semaphore may already have changed by the time sem_getvalue() returns. SEE ALSO <STRONG><A HREF="/man3/sem_post">sem_post(3)</A></STRONG>, <STRONG><A HREF="/man3/sem_wait">sem_wait(3)</A></STRONG>, <STRONG><A HREF="/man7/sem_overview">sem_overview(7)</A></STRONG> COLOPHON This page is part of release 5.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 <STRONG><A HREF="/man3/SEM_GETVALUE">SEM_GETVALUE(3)</A></STRONG></PRE> <center> <h6>Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2025 <a href="http://www.he.net">Hurricane Electric</a>. All Rights Reserved.</h6></center> </body> </html>