This sounds like a trivial question, but I couldn't easily find a solution around.
Here is my code:
#include <iostream>
#include <fcntl.h>
#include <semaphore.h>
using namespace std;
int main()
{
sem_t * my_semaphore = sem_open("./my_semaphore", O_CREAT, 0755, 1);
cout<<my_semaphore<<endl;
}
This prints out 0: the semaphore wasn't created. What am I doing wrong? I tested this code on an OSX environment and it worked perfectly.
The Linux manpage for sem_open says (emphasis added):
ENOENTTheO_CREATflag was not specified in oflag and no semaphore with this name exists; or,O_CREATwas specified, but name wasn't well formed.
The sem_overview says this about semaphore names:
A named semaphore is identified by a name of the form
/somename; that is, a null-terminated string of up toNAME_MAX-4(i.e., 251) characters consisting of an initial slash, followed by one or more characters, none of which are slashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With