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. |
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.
|
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 |
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! |
Re: Posix file based process shared semaphores
Quote:
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 |
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 |
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. |
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.
|
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.
|
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". :)
|
All times are GMT -5. The time now is 02:53 PM. |