Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

sem_getvalue(2) [hpux man page]

sem_getvalue(2) 						System Calls Manual						   sem_getvalue(2)

NAME
sem_getvalue - get the value of a POSIX semaphore SYNOPSIS
DESCRIPTION
is used to read the value of the semaphore. The value of the semaphore specified by sem is read, at some unspecified time during the call, and then stored into sval. If the semaphore value is <= 0, at that time, the semaphore is considered unavailable. If the semaphore value is > 0, at that time, the semaphore is considered available. If sval is positive, it is equal to the number of locks available on the semaphore, at the time the semaphore value was read. If sval is negative, its absolute value is equal to the number of blocked threads waiting for the semaphore to become available, at the time the sema- phore value was read. If the specified semaphore referred to by sem is a named semaphore, then this semaphore must have been opened by the calling process with and the process must have read permission on this semaphore. To use this function, link in the realtime library by specifying on the compiler or linker command line. EXAMPLES
The following call to will read the value of the semaphore sem and store it in sval. RETURN VALUE
A successful call to will return 0. Otherwise, the call to will return -1 with errno set to the appropriate value of the error condition. ERRORS
fails and does not perform the requested operation if any of the following conditions are encountered: [EPERM] The calling process does not have the privileges necessary to read the semaphore. [EINVAL] The argument sem does not refer to a valid semaphore. SEE ALSO
sem_open(2), <semaphore.h>. STANDARDS CONFORMANCE
sem_getvalue(2)

Check Out this Related Man Page

SEM_GETVALUE(3) 					   BSD Library Functions Manual 					   SEM_GETVALUE(3)

NAME
sem_getvalue -- get the value of a semaphore LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <semaphore.h> int sem_getvalue(sem_t * restrict sem, int * restrict sval); DESCRIPTION
The sem_getvalue() function sets the variable pointed to by sval to the current value of the semaphore pointed to by sem, as of the time that the call to sem_getvalue() is actually run. RETURN VALUES
The sem_getvalue() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The sem_getvalue() function will fail if: [EINVAL] The sem argument points to an invalid semaphore. SEE ALSO
sem_post(3), sem_trywait(3), sem_wait(3) STANDARDS
The sem_getvalue() function conforms to ISO/IEC 9945-1:1996 (``POSIX.1''). The value of the semaphore is never negative, even if there are threads blocked on the semaphore. POSIX is somewhat ambiguous in its wording with regard to what the value of the semaphore should be if there are blocked waiting threads, but this behavior is conformant, given the wording of the specification. BSD
February 15, 2000 BSD
Man Page

15 More Discussions You Might Find Interesting

1. Programming

semclt system call ???

hi mates, What is the : semctl system call for? any example will be helpful and be appreciated. cya and thanx abdul (2 Replies)
Discussion started by: abdul
2 Replies

2. UNIX for Dummies Questions & Answers

semaphore

hi, is there any command where we can monitor semaphores? (1 Reply)
Discussion started by: yls177
1 Replies

3. Programming

Example for use of kernel semaphore

Hi friends I'm doing a project and in that I need to use kernel semaphore but I'm not very clear about how to use it. I've used system V semaphore. What I find difficult to understand is that in system V semaphore, a semaphore set is registered to the system (the semid returned from semget call... (3 Replies)
Discussion started by: Rakesh Ranjan
3 Replies

4. Programming

change semaphore perm

Hi, I've a problem with this simple code about of semaphore: #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<semaphore.h> #include<sys/types.h> #include<sys/mman.h> #include<sys/fcntl.h> #define SemName "/SEM_1" int main (int argc, char **argv) { char name;... (5 Replies)
Discussion started by: FastMagister
5 Replies

5. Programming

semaphore limits

Hi Could anybody tell me how can i see the semaphore limits on my system. I am using solaris 8. Thanks in advance (2 Replies)
Discussion started by: axes
2 Replies

6. UNIX for Advanced & Expert Users

semaphore concept

Hi All, I am going through the semaphore concept and have a doubt regarding the same and hope to get a resolution here. I have a file which has a number of records. I want to write an application (in C) which will be able to do concurrent read/write on these records. Of what I have... (8 Replies)
Discussion started by: maverix
8 Replies

7. AIX

how to clean Unused semaphore??

How can i clean up my unused semaphore??? (4 Replies)
Discussion started by: abhishek27
4 Replies

8. Shell Programming and Scripting

How to read/process a .gz file, one line at a time?

Hello I'm stuck trying to solve this KSH issue and I'm hoping someone out there can offer some suggestions. I want to read lots of large .gz files one line at a time in order to compare its Error entries with a list of known errors. I can't simply do "foreach ERROR do gzcat *.gz |grep... (2 Replies)
Discussion started by: dayscripter
2 Replies

9. UNIX for Dummies Questions & Answers

Simultaneous file read operation

Hi All, I need information on file handling in UNIX enviornment. If in UNIX enviornment I have two process.. P1 P2 Both accessing the same file simultaneosuly(read operation).. Suppose P1 opened the file in read mode first and started reading the file.. Then P2 opens the same file in... (5 Replies)
Discussion started by: chibob
5 Replies

10. UNIX for Dummies Questions & Answers

Determining which processes hold a semaphore

I have a situation where I have created a semaphore and set it's value to 10. I am using this semaphore to control access to a shared memory location. I can have 10 processes simultaneously read from the shared memory location, process 11 would get locked out. My question is, is there a way I... (6 Replies)
Discussion started by: tpotter01
6 Replies

11. UNIX for Dummies Questions & Answers

semaphore

what is semaphore? can any body explain it in a more simple way than the manual ?? replies appreciated Regards raguram R (7 Replies)
Discussion started by: raguramtgr
7 Replies

12. Programming

Posix Semaphore Use - Releasing all resources?

I am attempting to write a program with multiple POSIX threads. I want to ensure all threads are released at the same time. I am (trying to) use a semaphore to accomplish this. Without too much irrelevant information, I declare my semaphore with 0 of 25 resources available. Is there a way... (7 Replies)
Discussion started by: snowbarr
7 Replies

13. Programming

semaphore memory

If say a process creates a semaphore/mutex etc then will this semaphore get created in its address space? If yes then how an another process which wants to acquire this semaphore(created by the first process) will access the other process address space to acquire the semaphore? Where I mean in... (2 Replies)
Discussion started by: rupeshkp728
2 Replies

14. Shell Programming and Scripting

File read time

hi, how to check the file latest read time.. (2 Replies)
Discussion started by: rsivasan
2 Replies

15. UNIX for Advanced & Expert Users

Semaphore - lockfile/flock

Hi, I have a process which can run one instance at a time. Currently we have multiple scripts trying to kickoff this process. I wanted to implement the semaphore mechanism to achieve this. I was going through few examples. The below code seems to be reasonable solution. ... (5 Replies)
Discussion started by: tostay2003
5 Replies