Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:14:30+00:00 2026-05-31T06:14:30+00:00

How to get the maximum number of semaphores possible in a semaphore set inside

  • 0

How to get the maximum number of semaphores possible in a semaphore set inside a c program?
The following program gets a set of 10 semaphored defined by the semaphore id semid

#include <sys/ipc.h>
#include <sys/sem.h>

key_t key;
int semid;

key = ftok("/home/somefile", 'E');
semid = semget(key, 10, 0666 | IPC_CREAT);

But what if i wanted to call the semget function so that it will always return a set of the maximum number of semaphores possibe in a system (SEMMSL, 250 in my case). It is not a #define statement. So is there a way of getting it other than opening the /proc/sys/kernel/sem file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:14:31+00:00Added an answer on May 31, 2026 at 6:14 am

    It sounds like you already have the answer– open /proc/sys/kernel/sem and call atoi() on the first number you read out. Sometimes, parsing the /proc filesystem is the best solution to a Linux problem.

    However, I grep’d for 250 in /usr/include/linux. It looks like the #define you seek lives in /usr/include/linux/sem.h:

    #define SEMMSL  250 
    

    So, assuming Linux headers are installed, you should be able to #include linux/sem.h and get access to that SEMMSL define.

    The trade-off here is that using the #define will hardcode SEMMSL into your binary. If you happen to move the binary to another machine that has a smaller number, I can see that causing a problem. FWIW, I just checked on x86_32, x86_64, and PowerPC Linux machines I’m running (all recent Ubuntu distros) and they all report 250. However, parsing through the /proc filesystem gives you the current limit for the running kernel, which strikes me as a better solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to set the maximum number of open files to some infinite
how can we get the maximum number of letters that are side-by-side? For example,
In Mathematica, Max[] is the most efficient function to get the maximum number in
How to get the maximum number of lines that can be written in TextView?
I need to get a value which has the maximum number of occurrences in
Hey guys, Im trying to get the maximum number of days in a database
Any one know what's the maximum number of shared regions is? Do you get
I created an app with minimum SDK 7 in order to get maximum compatibility
I need to get the maximum value out of this code, but it's really
How to get the maximum axis value from a created chart? Here is how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.