How to avoid multiple writers in a named pipe? How to avoid multiple writers in a named pipe? unix unix

How to avoid multiple writers in a named pipe?


This would be a typical use for semaphores:

  1. Create 2 semaphores - one for reading processed, the other one for writing processes. set each semaphore to value 1

  2. Reading processes sem_wait(2) on the semaphore for readers until semphore > 0 and lower it to zero if they get it.

  3. Writing processes will do the same with the semaphore intended for them

  4. A controlling process (which may also set up the semaphores initially) could check, if both semaphores are zero and assign the pair

  5. reader/writer release the semaphores (increasing them by 1 again) so next readr or writer will get the semaphore.

For passing informations between reader/writer shared memory may be used...