sem_open really strange behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm writing an application using semaphores. Here is a simple code recreating the problem:

***********************************************
#include <sys/types.h>
#include <stdio.h>
#include <semaphore.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>

int main()
{
  int ok;
//key_t t;
char *shm,*s;
sem_t *mutex;

  mutex = sem_open("/vik",O_CREAT|O_EXCL);
  if(mutex == SEM_FAILED)
    {
      perror("unable to create semaphore");
      sem_unlink("vik");
      exit(-1);
    }

  sem_close(mutex);
  sem_unlink("vik");
  exit(0);
}
************************************************

This, is going to generate "unable to create semaphore: Invalid argument" no matter how many times I execute it. It is compiled with "gcc sem.c -lrt"

However, once I uncomment the key_t line, everything works fine. What should be wrong? I'm stuck on this little thing for hours.

Thanks a lot in advance, Sergio.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux