Sponsored Content
Special Forums Hardware Filesystems, Disks and Memory semaphores and shared memory Post 22683 by ted on Saturday 8th of June 2002 12:06:31 PM
Old 06-08-2002
Question semaphores and shared memory

hello,
Can any one please answer these 2 questions?

1. What is the purpose of SEMAPHORES and SHARED MEMORY on a Unix platform?

2. What would require a SYS. ADMIN to set SEMAPHORES and SHARED MEMORY on a Unix platform?

Thanks,
Ted
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Shared memory shortage but lots of unused memory

I am running HP-UX B.11.11. I'm increasing a parameter for a database engine so that it uses more memory to buffer the disk drive (to speed up performance). I have over 5GB of memory not being used. But when I try to start the DB with the increased buffer parameter I get told. "Not... (1 Reply)
Discussion started by: cjcamaro
1 Replies

2. Programming

help with shared memory

what i want to do is have an int that can been written into by 2 processes but my code doesn't seem to work. #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <sys/shm.h> #include<stdio.h> #define KEY1 (1492) int main() { int shmid; volatile int * addr;... (6 Replies)
Discussion started by: ddx08
6 Replies

3. Programming

memory sharing - not shared memory -

hi, this is the problem: i want to swap a linked list between 4 processes (unrelated), is there any way i can do that just by sending a pointer to a structure? //example typedef struct node { int x; char c; struct node *next; } node; or i should send the items ( x,c ) by... (9 Replies)
Discussion started by: elzalem
9 Replies

4. Programming

Shared memory in shared library

I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
Discussion started by: DreamWarrior
12 Replies

5. Programming

Shared memory for shared library

I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability. Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Discussion started by: otheus
0 Replies

6. UNIX for Advanced & Expert Users

Shared Memory

Hi, Using ipcs we can see shared memory, etc.. details. How can I add/remove shared memory(command name)? Thanks, Naga:cool: (2 Replies)
Discussion started by: Nagapandi
2 Replies

7. AIX

shared memory

1.How to know wich process is using the shared memory? 2.How to flush (release) the process from the shared memory? (1 Reply)
Discussion started by: pchangba
1 Replies

8. Programming

Airport using semaphores and shared memo

Hi just doin' this here for the naval school, back here in Pportugal, and needed some help, especially with the shared memo i want to use for the 10 airport gate, and the maximum of 4 planes preparing to leave; canīt figure out how the gate can be id by the same PID. WELL, if someone wants to... (1 Reply)
Discussion started by: Turbo
1 Replies

9. Homework & Coursework Questions

Airport using semaphores and shared memo

Hi just doin' this here for the naval school, back here in Pportugal, and needed some help, especially with the shared memo i want to use for the 10 airport gate, and the maximum of 4 planes preparing to leave; canīt figure out how the gate can be id by the same PID. WELL, if someone wants to... (2 Replies)
Discussion started by: Turbo
2 Replies

10. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies
SEMAPHORES(3)						     Library Functions Manual						     SEMAPHORES(3)

NAME
sem_init, sem_wait, sem_trywait, sem_post, sem_getvalue, sem_destroy - operations on semaphores SYNOPSIS
#include <semaphore.h> int sem_init(sem_t *sem, int pshared, unsigned int value); int sem_wait(sem_t * sem); int sem_trywait(sem_t * sem); int sem_post(sem_t * sem); int sem_getvalue(sem_t * sem, int * sval); int sem_destroy(sem_t * sem); DESCRIPTION
This manual page documents POSIX 1003.1b semaphores, not to be confused with SystemV semaphores as described in ipc(5), semctl(2) and semop(2). Semaphores are counters for resources shared between threads. The basic operations on semaphores are: increment the counter atomically, and wait until the counter is non-null and decrement it atomically. sem_init initializes the semaphore object pointed to by sem. The count associated with the semaphore is set initially to value. The pshared argument indicates whether the semaphore is local to the current process ( pshared is zero) or is to be shared between several pro- cesses ( pshared is not zero). LinuxThreads currently does not support process-shared semaphores, thus sem_init always returns with error ENOSYS if pshared is not zero. sem_wait suspends the calling thread until the semaphore pointed to by sem has non-zero count. It then atomically decreases the semaphore count. sem_trywait is a non-blocking variant of sem_wait. If the semaphore pointed to by sem has non-zero count, the count is atomically decreased and sem_trywait immediately returns 0. If the semaphore count is zero, sem_trywait immediately returns with error EAGAIN. sem_post atomically increases the count of the semaphore pointed to by sem. This function never blocks and can safely be used in asynchro- nous signal handlers. sem_getvalue stores in the location pointed to by sval the current count of the semaphore sem. sem_destroy destroys a semaphore object, freeing the resources it might hold. No threads should be waiting on the semaphore at the time sem_destroy is called. In the LinuxThreads implementation, no resources are associated with semaphore objects, thus sem_destroy actually does nothing except checking that no thread is waiting on the semaphore. CANCELLATION
sem_wait is a cancellation point. ASYNC-SIGNAL SAFETY On processors supporting atomic compare-and-swap (Intel 486, Pentium and later, Alpha, PowerPC, MIPS II, Motorola 68k), the sem_post func- tion is async-signal safe and can therefore be called from signal handlers. This is the only thread synchronization function provided by POSIX threads that is async-signal safe. On the Intel 386 and the Sparc, the current LinuxThreads implementation of sem_post is not async-signal safe by lack of the required atomic operations. RETURN VALUE
The sem_wait and sem_getvalue functions always return 0. All other semaphore functions return 0 on success and -1 on error, in addition to writing an error code in errno. ERRORS
The sem_init function sets errno to the following codes on error: EINVAL value exceeds the maximal counter value SEM_VALUE_MAX ENOSYS pshared is not zero The sem_trywait function sets errno to the following error code on error: EAGAIN the semaphore count is currently 0 The sem_post function sets errno to the following error code on error: ERANGE after incrementation, the semaphore value would exceed SEM_VALUE_MAX (the semaphore count is left unchanged in this case) The sem_destroy function sets errno to the following error code on error: EBUSY some threads are currently blocked waiting on the semaphore. AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
pthread_mutex_init(3), pthread_cond_init(3), pthread_cancel(3), ipc(5). LinuxThreads SEMAPHORES(3)
All times are GMT -4. The time now is 06:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy