title: Why can't I interact with a System V semaphores I've created?
body: <p>I'm trying to use System V semaphores in C for a lab but my courses aren't helping me.</p>
  
  <p>I can create my semaphore and delete it (using semget() and semctl()), but I can't interact with it: its value always stays the same (0) and it doesn't do it's semaphore job when I ask it to (with semop()).</p>
  
  <p>By the way, I extracted below the code I already wrote concerning my semaphore:</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/ipc.h&gt;
  #include &lt;sys/sem.h&gt;
  
  int main()
  {
      // some code
  
      int sem;
  
      struct sembuf up = {0,1,0};
      struct sembuf down = {0,-1,0};
  
      sem = semget(IPC_PRIVATE, 1, 777 | IPC_CREAT);
         // Tried with 777 because why not. Originally at 600
         // but it gave me a "Permission denied" error.
  
      semop(sem, &amp;up, 1); // up
  
      // some critical code
  
      semop(sem, &amp;down, 1); // ... and down
      semctl(sem, 0, IPC_RMID); // deletion
  }
  </code></pre>
  
  <p>Does someone know what's missing in my code to make my semaphore work?</p>
  
  <p>NB: No, I can't use POSIX semaphores. Yes I know that's sad.</p>