title: Find the maximum number of semaphores that one process can have open at a time
body: <p>To find maximum number of semaphores that one process can have open at a time, I didn't get why below code <code>_SC_SEM_NSEMS_MAX</code> returns <code>-1</code>.</p>
  
  <pre><code>int main(void) {
          long max_limit = 0;
          errno = EINVAL;
          max_limit = sysconf(_SC_SEM_NSEMS_MAX);
          printf("max_limit : %ld error_no : %d\n",max_limit,errno);
  
          return 0;
  } 
  </code></pre>
  
  <p><strong>Edit :-</strong> Here is what I tried to get the max limit manually.</p>
  
  <pre><code>struct count {
          sem_t sem_addr;
          int count;
  };
  int main(void) {
          int fd = 0,zero = 0;
          struct count *shared;
          fd = shm_open("/my_semaphore",O_RDWR|O_CREAT,0777);
          if(fd == -1){
                  perror("shm_open");
                  exit(0);
          }
          //ftruncate(fd,4096);
          write(fd,&amp;zero,4);
          shared = mmap(NULL,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd,(off_t)0);
          sem_init(&amp;shared-&gt;sem_addr,1,1);
  
          pid_t pid = fork();
          if(pid &gt; 0) {
                  //printf("parent process: %d \n",getpid());
                  sem_wait(&amp;shared-&gt;sem_addr);
                  for(int i = 0;i &lt; 50 ;i++) {
                          printf("parent = %d \n",shared-&gt;count++);
                  }
                  sem_post(&amp;shared-&gt;sem_addr);
          }
          else if (pid == 0) {
                  //printf("child process: %d \n",getpid());
                  sem_wait(&amp;shared-&gt;sem_addr);
                  for(int i = 0;i &lt; 50 ;i++) {
                          printf("child = %d \n",shared-&gt;count++);
                  }
                  sem_post(&amp;shared-&gt;sem_addr);
          }
          sem_destroy(&amp;shared-&gt;sem_addr);
          return 0;
  }
  </code></pre>
  
  <p>Any help will be appreciated.</p>