LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 11-16-2002, 09:32 PM   #1
dragonman
LQ Newbie
 
Registered: Nov 2002
Posts: 2

Rep: Reputation: 0
Question Posix file based process shared semaphores


I am trying to program Posix file based process shared semaphores and Posix shared memory with gcc version 2.96 on my system with a Linux 2.4.7-10 kernel. I've run the posixtst program which indicates that my kernel should support Posix semaphores and shared memory. However, the man pages have no information on the file based semaphore calls, sem_open() and sem_unlink(), or shared memory calls such as shm_open() and shm_unlink(). Furthermore, when compiling with a header include statement for semaphore.h and sys/mman.h, all semaphore and shared memory calls are reported as undefined references. I have also attempted to compile with sys/ipc.h, sys/sem.h, and sys/shm.h (which are all System V) in addition to the headers named above. In addition, I have seen university text that said process shared Posix semaphores are not supported in Linux. Is this true? If not, is there an include or a library I need during compile that would add support for these calls?

Thanks.

Steve Davis.
 
Old 11-17-2002, 11:26 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
You can link to calls in semaphore.h with -lpthread. Shared memory calls in sys/mman.h: shm_open and others are in -lrt. That is what nm is reporting.
 
Old 08-14-2003, 10:14 AM   #3
stephen_wu
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
i linked -lrt, but my program still aborted. use strerror(errno),i got the following info:function not implemented.
my os is slackware linux ,kernel is 2.4.18.gcc 3.2.2

should i mount tmpfs or something?

thanks
 
Old 08-14-2003, 11:03 AM   #4
stephen_wu
LQ Newbie
 
Registered: Aug 2003
Posts: 2

Rep: Reputation: 0
i mount tmpfs,and i got the following info:
No such file or directory

my code is like this:
if ((fd = shm_open(alloc_key_ss.str().data(), O_RDWR, S_IRWXU | S_IRWXG)) == -1) {...}
and i tested alloc_key_ss.str().data(),it exist!

i got puzzled!
 
Old 03-13-2005, 03:17 AM   #5
neerajgups
LQ Newbie
 
Registered: Mar 2005
Posts: 1

Rep: Reputation: 0
Re: Posix file based process shared semaphores

Quote:
Originally posted by dragonman
I am trying to program Posix file based process shared semaphores and Posix shared memory with gcc version 2.96 on my system with a Linux 2.4.7-10 kernel. I've run the posixtst program which indicates that my kernel should support Posix semaphores and shared memory. However, the man pages have no information on the file based semaphore calls, sem_open() and sem_unlink(), or shared memory calls such as shm_open() and shm_unlink(). Furthermore, when compiling with a header include statement for semaphore.h and sys/mman.h, all semaphore and shared memory calls are reported as undefined references. I have also attempted to compile with sys/ipc.h, sys/sem.h, and sys/shm.h (which are all System V) in addition to the headers named above. In addition, I have seen university text that said process shared Posix semaphores are not supported in Linux. Is this true? If not, is there an include or a library I need during compile that would add support for these calls?

Thanks.

Steve Davis.
Hi Steve,

Did you get any soln. to your problem(s)? I ran into similar problems when trying something similar on Suse Linux 9.0 (Kernel: 2.4.21-199). sem_open: gives "Function not implemented" ans does sem_close(). I've been trying to implement POSIX semaphores, but it is a wee bit tricky. Please do let me know if you come across any website having the source code etc. or if you've fixed your problem.

Thanks a tonne,
Neeraj
 
Old 04-05-2005, 07:28 PM   #6
ceoping
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
Question Is POSIX semaphores supported in Linux at all?

I am having the same issue and wonder if any one has the answer to this question. I would appricate if you would post it. I read mixed reports saying that support for shared-memory and semaphores are not fully supported in Linux and some reports saying that the standards are out there now for Linux. I was going to use System V because of its wide implementation, but read that that standards body has evaporated or merged and POSIX is the way to go. Any clarification or source reference would be appreciated.

Thanks,

kl
 
Old 04-05-2005, 07:37 PM   #7
ceoping
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
I posted a reply from gotom for a similar issue hoping that it may help some of you...

Because you don't mount tmpfs on /dev/shm. Please use the newer glibc
(>= 2.3.2.ds1-11) or install the latest "initscripts". I guess you
may disable tmpfs on /dev/shm.
 
Old 05-02-2005, 10:30 AM   #8
cjSlominski
LQ Newbie
 
Registered: May 2005
Posts: 1

Rep: Reputation: 0
Named semaphores in Linux

I have just run into this same problem and I did not see that any of the posts answered the question. I have written software to use POSIX named semaphores, which can be used between different processes on the same host. I wrote the software to be used on several different platforms and have successfully used it on other UNIX platforms. It won't build under Linux because it appears to only support POSIX thread semaphores; you can't do a sem_open, sem_unlink. Is this capability scheduled to be included in Linux? We use kernel version 2.4 in Redhat enterprise workstation 3.
 
Old 05-19-2005, 02:21 PM   #9
ceoping
LQ Newbie
 
Registered: Apr 2005
Posts: 6

Rep: Reputation: 0
You can build on linux 2.4, but you have to run on linux 2.6 (for example, SUSE 9). Linux 2.4 does not have the full support. If you have trouble building, include -lrt to the linker. I hope this helps.
 
Old 05-25-2005, 04:44 PM   #10
MeMooMeM
LQ Newbie
 
Registered: May 2005
Posts: 8

Rep: Reputation: 0
Be careful with Linux!

I am also using POSIX with Linux, and realized that you must be very careful while doing that. For example, sem_open returns to 0 instead of -1 on error!! I'd recommend you to use the standard names; such as "SEM_FAILED" instead of "-1".
 
  


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
Shared Memory/ Semaphores wildem Programming 3 06-20-2005 01:13 PM
POSIX shared memory confusion MeMooMeM Programming 0 05-25-2005 04:32 PM
POSIX semaphores acting strangely spuzzzzzzz Programming 0 10-18-2004 09:10 PM
shared memory and semaphores... socket9001 Programming 3 02-16-2004 11:18 AM
POSIX File-based Semaphores dragonman Linux - Newbie 1 11-17-2002 10:51 AM

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

All times are GMT -5. The time now is 10:44 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