top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Share POSIX semaphore among multiple processes

+1 vote

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 LinkedIn 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 :

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
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.