LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   What is the state of Posix Semaphore Support? (https://www.linuxquestions.org/questions/programming-9/what-is-the-state-of-posix-semaphore-support-307791/)

jhtrauntvein 03-30-2005 09:40 AM

What is the state of Posix Semaphore Support?
 
I am in the process of porting a program and supporting library from Win32 to what I hope to be various flavours of unix including Linux and Darwin. The program that I am porting uses a named Win32 mutex object to prevent multiple instances of the program from using the same "working directory". I need to replicate this capability under unix and believe that I can accomplish this using posix semaphores. The book that I am using (Advanced Unix Programming by Marc Rochkind) states that posix semaphores are not supported under Linux, FreeBSD, or Darwin. I have done more searching on the web and have turned up some evidence that refutes this statement with regards to linux but have been unable to find anything that states conclusively that posix semaphores are, in fact, supported in various versions of the linux kernel. I would welcome help from anybody that can give me more conclusive information as well as any guidance on the above mentioned porting issue.

Regards,

Jon Trauntvein

aluser 03-30-2005 07:53 PM

the two typical semaphore apis you'll generally find are the posix threads sem_* functions, which work only within a threaded process, and sysV semaphores via semget(), semctl(), and semop().

If you can write your working directory, it'd probably be easiest to just create a lockfile in it. (Use open() with O_CREAT|O_EXCL)

If you wanted to have just one instance per user, it'd be typical to create a lockfile in a dot directory in $HOME.

jonaskoelker 05-26-2005 09:02 AM

Quote:

Use open() with O_CREAT|O_EXCL
For clarification: that's not really portable (say, back to w32), is it?
More important: is it atomic (process-safe)? I recall reading (regarding some PHP) that using directories was better.

--Jonas

aluser 05-26-2005 11:44 AM

It's definitely atomic. I'm not sure about portable to win32. The man page seems to say that it is POSIX.


All times are GMT -5. The time now is 02:21 AM.