What I'm currently working on requires a couple of posix semaphores to be initialized inside of a function that multiple processes will be running, and the semaphores will be shared with another function where those processes will also be running. How do I go about this so that the semaphores are only created once by one thread, while the rest only open them? I can't seem to find anything about how to do this anywhere.
All I can find on the subject is about how to use the sem_wait() and sem_post() functions, but nothing specific to my problem. I also had to make sure that a file was created only once and opened by the other processes, but the file can be checked whether or not it's been created already by the access() function. Is there anything like that for semaphores?
Any help in explaining how this is done would be greatly appreciated.