sem_getvalue(3) Library Functions Manual sem_getvalue(3)NAME
sem_getvalue - Gets the value of a specified semaphore (P1003.1b)
LIBRARY
Realtime Library (librt.so, librt.a)
SYNOPSIS
#include <semaphore.h>
int sem_getvalue (
sem_t *sem,
int *sval);
PARAMETERS
sem Specifies a pointer to the semaphore for which a value is to be returned.
sval References a location to be updated with the value of the semaphore indicated by the sem argument.
DESCRIPTION
The sem_getvalue function updates a location referenced by the sval argument with the value of semaphore sem. The updated value represents
an actual semaphore value that occurred during the call, but may not be the actual value of the semaphore at the time that the value is
returned to the calling process.
If the semaphore is locked, the value returned will either be zero or a negative number indicating the number of processes waiting for the
semaphore at some time during the call.
RETURN VALUES
On a successful call, a value of 0 (zero) is returned. Otherwise, a value of -1 is returned and errno is set to indicate that an error
occurred.
ERRORS
The sem_getvalue function fails under the following condition:
[EINVAL] The sem argument does not refer to a valid semaphore.
RELATED INFORMATION
Functions: sem_post(3), sem_trywait(3), sem_wait(3)
Guide to Realtime Programming delim off
sem_getvalue(3)
Check Out this Related Man Page
sem_wait(3) Library Functions Manual sem_wait(3)NAME
sem_wait, sem_trywait - Performs (or conditionally performs) a semaphore lock (P1003.1b)
LIBRARY
Realtime Library (librt.so, librt.a)
SYNOPSIS
#include <semaphore.h>
int sem_wait (
sem_t *sem);
int sem_trywait (
sem_t *sem);
PARAMETERS
sem Specifies a pointer to the semaphore to be locked.
DESCRIPTION
The sem_wait function locks the semaphore referenced by sem by performing a semaphore lock operation on it. If the semaphore value is zero,
the sem_wait function blocks until it either locks the semaphore or is interrupted by a signal.
The sem_trywait function locks a semaphore only if the semaphore is currently not locked. If the semaphore value is zero, the sem_trywait
function returns without locking the semaphore.
These functions help ensure that the resource associated with the semaphore cannot be accessed by other processes. The semaphore remains
locked until the process unlocks it with a call to the sem_post function.
Use the sem_wait function instead of the sem_trywait function if the process should wait for access to the semaphore.
RETURN VALUES
If the sem_wait or sem_trywait function returns successfully, a value of 0 (zero) is returned and the function executes the semaphore lock
operation.
On an unsuccessful call, a value of -1 is returned and errno is set to indicate that an error occurred. The state of the semaphore remains
unchanged.
ERRORS
The sem_wait and sem_trywait functions fail under the following conditions:
[EAGAIN] The semaphore was already locked and cannot be locked by the sem_trywait operation (sem_trywait only).
[EINTR] A signal interrupted this function.
[EINVAL] The sem argument does not refer to a valid semaphore.
RELATED INFORMATION
Functions: sem_post(3)
Guide to Realtime Programming delim off
sem_wait(3)
When I execute the first 4 lines of code , it works fine. But the output gives a segmentation fault on executing the sem_getvalue() function. I looke up everywhere for the syntax and other mistakes but I am not being able to find out whats wrong with the code. Can anyone please help me on that...??... (8 Replies)
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)
Hello All,
I have some files like file, file.chk, file.sem and file.temp in huge. I would like to delete some files based on following criteria.
1. Unconditionally delete .sem and .temp files
2. If we found the actual file, don't remove .chk file, otherwise remove .chk file as well
for... (5 Replies)