Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sem_open returns Errno 0

807559Mar 18 2002 — edited Apr 17 2002
I 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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2002
Added on Mar 18 2002
1 comment
360 views