sem_open returns Errno 0
807559Mar 18 2002 — edited Apr 17 2002I am trying to implement Producer consumer problem using POSIX semaphores.
The function sem_open() returns the errno =0. It fails to create the named semaphore.
Here is the simple implemenation of sem_open() function which fails returning errno 0.
#include <semaphore.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <errno.h>
void main() {
const char *mutex = "/test1.1234";
sem_t *lock;
int errval;
int chk;
chk = sem_unlink(mutex);
printf("chk = %d\n",chk);
lock = sem_open(mutex, O_CREAT | O_EXCL, 0644, 1);
errval = errno;
printf ("Error = %d, Means = %s \n", errval, strerror(errval));
printf("Lock = %d\n", lock);
if(SEM_FAILED) {
perror("Sem Open Failed\n");
}
}
Can anybody help me how to resolve this issue.
Thank you,
Raji.