Posix semaphore in the Linux (RHEL4)



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;
}

====================================================================

.