LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2005, 09:40 AM   #1
jhtrauntvein
LQ Newbie
 
Registered: Mar 2005
Distribution: Fedora
Posts: 2

Rep: Reputation: 0
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
 
Old 03-30-2005, 07:53 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
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.
 
Old 05-26-2005, 09:02 AM   #3
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
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
 
Old 05-26-2005, 11:44 AM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to upgrade to glibc2.3.4(POSIX support) emblin Linux - General 4 09-09-2005 04:49 PM
not able to upgrade to glibc2.3.4(POSIX support) emblin Programming 0 09-06-2005 03:56 AM
does rh9.0 support POSIX message queue? simon_qwl Programming 1 07-22-2005 05:25 PM
POSIX Msg Q support for MontaVista pro 3.1 ashishkb Linux User Groups (LUG) 1 06-15-2004 04:30 PM
POSIX Message Q support for Monta Vista pro 3.1 ashishkb Linux User Groups (LUG) 2 05-28-2004 03:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration