Sponsored Content
Full Discussion: semaphores using up and down
Top Forums Programming semaphores using up and down Post 302113006 by ddx08 on Monday 2nd of April 2007 06:30:51 PM
Old 04-02-2007
semaphores using up and down

been searching around on how to use an up and down function with semaphores but i can't find an example. i looked into using: "semop" but i have no idea how to use it. I have been able to declared the semaphores using semget and initializing them using semctl.
 

10 More Discussions You Might Find Interesting

1. Programming

Semaphores

Dear Reader, I'm in a multiprocess environment working with shared mem and semaphores as mutex.. The problem is -- If one of the process hooked up with the semaphore and accessing the shared mem, terminates abruptly ( or got killed ), other process which are in want of the semaphore are... (1 Reply)
Discussion started by: joseph_shibu
1 Replies

2. UNIX for Dummies Questions & Answers

Semaphores

Hi all, I am using HP 10.20 on A 9000/785. My question is: If I am the only person logged in as root at the moment, how many "semaphore proccesses" should I have?? Is it only one, or it is relevant to other system proccesses? Here is what I get listing the current semaphores # ipcs -sp... (1 Reply)
Discussion started by: guest100
1 Replies

3. Programming

semaphores

Hi there, Could someone please confirm which POSIX semaphore routines should be used for a multiprocess (and not multithreaded) environment? sys/sem.h definitely works. but the routines, semget, semctl, semop are pretty unwieldy. So, I am looking for an easier way out. From the man pages... (2 Replies)
Discussion started by: qntmteleporter
2 Replies

4. Shell Programming and Scripting

semaphores

Hi Friends, If i execute this command it comes back with 300 lines: ipcs|grep cerebrus >>> i would like to clear the semaphores but ipcrm can remove one id at a time. is there a quicker way of removing semaphores maybe using awk? Regards, (1 Reply)
Discussion started by: kekanap
1 Replies

5. UNIX for Advanced & Expert Users

How many semaphores?

Hello, first of all I apologize if this thread is not in the correct section of this forum, but this one just seemed the most appropriate. The question I have does not concern Unix specifically, it applies to virtually any OS, however it is in Unix where I learned about this problem. So, the... (8 Replies)
Discussion started by: Watto86
8 Replies

6. Programming

Semaphores Urgent

Hello, Iam trying to implement the sleeping barber problem using semaphores and running on UNIX machine. Iam linking it to the thread libraries : bash-2.03$ g++ sleepingBarber.cpp -lpthread -o sleeping but when i execute it i get the following error: bash-2.03$ sleeping Starting Program... (4 Replies)
Discussion started by: mohit.choudhary
4 Replies

7. Programming

Problem with semaphores

Hello, I was doing an exercise of semaphores and shared memory, namely the barbers: -B number of barbers -S number of chairs -C number of customers. I have done already and I compiled the code, but when run I get an error segment. Can not be and it took several days. If anyone sees the error... (2 Replies)
Discussion started by: ciudadwifi
2 Replies

8. UNIX for Dummies Questions & Answers

semaphores

I am having problem with semaphores. I am trying to protect line where process prints so that every process with print in proper order.This is the code.. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include <sys/sem.h> #include <sys/types.h> union... (3 Replies)
Discussion started by: joker40
3 Replies

9. Programming

about Semaphores

Hello Everybody, I am building a server. this server contains some data. Clients may modify this data or read this data. If a client is reading the data and at the same time another client is modifying the data then at this case the reading client may read some false data (some old mixed with... (1 Reply)
Discussion started by: Omar_Mokhtar
1 Replies

10. Solaris

Semaphores

Hi, Can somebody please explain me what semaphores are? there purpose? and there effects? Thanks in advance:) (0 Replies)
Discussion started by: Laxxi
0 Replies
SEM_OVERVIEW(7) 					     Linux Programmer's Manual						   SEM_OVERVIEW(7)

NAME
sem_overview - overview of POSIX semaphores DESCRIPTION
POSIX semaphores allow processes and threads to synchronize their actions. A semaphore is an integer whose value is never allowed to fall below zero. Two operations can be performed on semaphores: increment the semaphore value by one (sem_post(3)); and decrement the semaphore value by one (sem_wait(3)). If the value of a semaphore is currently zero, then a sem_wait(3) operation will block until the value becomes greater than zero. POSIX semaphores come in two forms: named semaphores and unnamed semaphores. Named semaphores A named semaphore is identified by a name of the form /somename; that is, a null-terminated string of up to NAME_MAX-4 (i.e., 251) characters consisting of an initial slash, followed by one or more characters, none of which are slashes. Two processes can operate on the same named semaphore by passing the same name to sem_open(3). The sem_open(3) function creates a new named semaphore or opens an existing named semaphore. After the semaphore has been opened, it can be operated on using sem_post(3) and sem_wait(3). When a process has finished using the semaphore, it can use sem_close(3) to close the semaphore. When all processes have finished using the semaphore, it can be removed from the system using sem_unlink(3). Unnamed semaphores (memory-based semaphores) An unnamed semaphore does not have a name. Instead the semaphore is placed in a region of memory that is shared between multiple threads (a thread-shared semaphore) or processes (a process-shared semaphore). A thread-shared semaphore is placed in an area of memory shared between the threads of a process, for example, a global variable. A process-shared semaphore must be placed in a shared memory region (e.g., a System V shared memory segment created using shmget(2), or a POSIX shared memory object built created using shm_open(3)). Before being used, an unnamed semaphore must be initialized using sem_init(3). It can then be operated on using sem_post(3) and sem_wait(3). When the semaphore is no longer required, and before the memory in which it is located is deallocated, the semaphore should be destroyed using sem_destroy(3). The remainder of this section describes some specific details of the Linux implementation of POSIX semaphores. Versions Prior to kernel 2.6, Linux supported only unnamed, thread-shared semaphores. On a system with Linux 2.6 and a glibc that provides the NPTL threading implementation, a complete implementation of POSIX semaphores is provided. Persistence POSIX named semaphores have kernel persistence: if not removed by sem_unlink(3), a semaphore will exist until the system is shut down. Linking Programs using the POSIX semaphores API must be compiled with cc -pthread to link against the real-time library, librt. Accessing named semaphores via the filesystem On Linux, named semaphores are created in a virtual filesystem, normally mounted under /dev/shm, with names of the form sem.somename. (This is the reason that semaphore names are limited to NAME_MAX-4 rather than NAME_MAX characters.) Since Linux 2.6.19, ACLs can be placed on files under this directory, to control object permissions on a per-user and per-group basis. NOTES
System V semaphores (semget(2), semop(2), etc.) are an older semaphore API. POSIX semaphores provide a simpler, and better designed inter- face than System V semaphores; on the other hand POSIX semaphores are less widely available (especially on older systems) than System V semaphores. EXAMPLE
An example of the use of various POSIX semaphore functions is shown in sem_wait(3). SEE ALSO
sem_close(3), sem_destroy(3), sem_getvalue(3), sem_init(3), sem_open(3), sem_post(3), sem_unlink(3), sem_wait(3), pthreads(7), shm_over- view(7) COLOPHON
This page is part of release 4.15 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-05-03 SEM_OVERVIEW(7)
All times are GMT -4. The time now is 11:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy