title: Why does semget() cause an EACCES error when *creating* a semaphore?
body: <p>I have to make a semaphore array for a C++ project. I'm not calling <code>semget()</code> from <code>main()</code>; I've got a separate method to make it easier, albeit a method in <code>main.cpp</code>. When my program reaches <code>semget(semkey,nsems,0666|IPC_CREAT)</code>, it returns -1 with an EACCES errno, which apparently means "A semaphore identifier exists for <code>key</code>, but operation permission as specified by the low-order 9 bits of <code>semflg</code> would not be granted."</p>
  
  <p>I've gone over and over my code with GDB. All three parameters for <code>semget()</code> look right, and this is the first point at which the program call <code>semget()</code>, so the semaphore doesn't exist already; I even ran <code>ipcs -s</code> to make sure. I've got <code>#include &lt;sys/sem.h&gt;</code> at the top of <code>main.cpp</code>.</p>
  
  <p>What's going on here? I've already created and attached a shared memory segment, could that have something to do with it? I can't see how.</p>