Suppose I have a parent that forks a child. The forked child then uses exec() to change it's process image. Both child and parent are now doing active data exchange using a pipe. I want to synchonize this data exchange using a semaphore. From what I understand I will create the semaphore in the parent before fork. However will the child, after exec() be able to access this semaphore? If not, is there some other way I can use a semaphore to establish synchonization?
1 Answers
1
votes
From the exec man page:[SEM] Any named semaphores open in the calling process shall be closed as if by appropriate calls to sem_close().
So after calling exec, you can't reach any open semephores in the parent.
Of course, you don't have to worry about that at all, if you want two processes to share a semaphore just use posix named semaphores.
The idea is simple, you create a semaphore in a process and give it a name; the other process just has to have the name and it then can open that semaphore.