top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Share POSIX semaphore among multiple processes

+1 vote
44 views

I need to create two child processes each of which calls its own execvp on fork and the executable share common POSIX semaphores between them.
So do I need to create a shared memory or just implement named semaphores?

posted Aug 25, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

I think you must create shared memory using shm_open(). Then create the semaphore for the shared memory.

When you are creating the semaphore, you are indicating whether the semaphore is shared between 2 threads or 2 processes.
with the help of the pshared variable. You should use pshared as a non-zero value to say it's an inter proecess semaphore.

int sem_init(sem_t *sem, int pshared, unsigned int value);

Please see :
http://man7.org/linux/man-pages/man3/sem_init.3.html
and
http://man7.org/linux/man-pages/man3/shm_open.3.html

answer Aug 27, 2015 by Sudeep Gopal
Similar Questions
0 votes

Please explain with real life example?

+1 vote

I know the basics of pthread but looking for more information on uses of pthread_detach library function.

+1 vote

I am using for loop. In for loop there is one system call OR POSIX API (EX : read , write, fopen, fclose, open, close , pthread_create etc...)
How can I calculate the complexity of program. Is there any link where I can see code of system call or complexity ??

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...