Posix semaphore in the Linux (RHEL4)
- From: "cyril.li@xxxxxxxxx" <cyril.li@xxxxxxxxx>
- Date: 22 Mar 2006 21:12:25 -0800
Hi,
I try to use the posix semaphore for two processes, see the code in the
following.
In the "man sem_init", it is said that "LinuxThreads currently does not
sup-port process-shared semaphores, thus sem_init always returns
with error ENOSYS if pshared is not zero.", but it works when I tried
using root.
The strange thing is that, when I login the system as normal user, the
sem_open() will fail. Has anybody know the reason?
==================================================================
#include <semaphore.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
sem_t *st;
int val;
st = sem_open("mytest", O_RDWR | O_CREAT, 0x666, 0);
if (st == SEM_FAILED) {
printf("SEM_FAILED\n");
}
sem_init(st, 1, 0);
sem_getvalue(st, &val);
printf("sem val: %d\n", val);
sem_wait(st);
printf("hello\n");
return 0;
}
===================================================================
#include <semaphore.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(void)
{
sem_t *st;
st = sem_open("mytest", O_RDWR);
if (st == SEM_FAILED) {
printf("SEM_FAILED\n");
}
sem_post(st);
printf("post\n");
return 0;
}
====================================================================
.
- Follow-Ups:
- Re: Posix semaphore in the Linux (RHEL4)
- From: Mikko Rauhala
- Re: Posix semaphore in the Linux (RHEL4)
- From: Jordan Abel
- Re: Posix semaphore in the Linux (RHEL4)
- Prev by Date: Re: Is stork a troll? (was Re: Trolltech QT license question)
- Next by Date: Re: Posix semaphore in the Linux (RHEL4)
- Previous by thread: GNOME: How to display an URL in the default webbrowser.
- Next by thread: Re: Posix semaphore in the Linux (RHEL4)
- Index(es):