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 8416901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:51+00:00 2026-06-10T01:53:51+00:00

I want to get the value of kernel.shmmax in C code (which I query

  • 0

I want to get the value of kernel.shmmax in C code (which I query on centos5.0, centos6.0 and ubuntu10.04 using the shell command “$ sysctl -q kernel.shmmax”).

I used the following code to find it:

#include <sys/sysctl.h>

const int SHM_ERROR=1;

main(){
    int name[] = {KERN_SHMMAX};
    int namelen = 1;
    int oldval[1];
    size_t oldlen = sizeof(oldval);
    int rv = sysctl(name, namelen, (void*) oldval, &oldlen, NULL, 0);
    if (rv!=0) {
        fprintf(stderr, "while quering for shared memory size, sysctl returned error: %s\n", strerror(errno));
        return SHM_ERROR;
    }
    else{
        return 0;
    }
}

After running the code above I get the following error:

while quering for shared memory size, sysctl returned error: Not a directory

I am clueless about why I am getting this error. I googled for it and found there is some issue with the paths into which library tries to look into.

I tried running the above code with GDB but the code doesn’t steps into the function sysctl, otherwise I could have provided you more information.

Data point:
I am easily able to set and get kernel.shmmax from command line on all the operating systems mentioned using the following commands:

$ sysctl -q kernel.shmmax

$ sysctl -w kernel.shmmax=1000000000

Thanks

  • 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-06-10T01:53:53+00:00Added an answer on June 10, 2026 at 1:53 am

    You shouldn’t be calling sysctl from userspace code. From the man page:

    Glibc does not provide a wrapper for this system call; call it using
    syscall(2).

    Or rather… don’t call it: use of this system call has long been
    discouraged, and it is so unloved that it is likely to disappear in a
    future kernel version
    . Remove it from your programs now; use the
    /proc/sys interface instead.

    So give this a shot instead:

    #include <stdio.h>                                                                                                                  
    
    #define SHMMAX_SYS_FILE "/proc/sys/kernel/shmmax"
    
    int main(int argc, char **argv)
    {
        unsigned int shmmax;
        FILE *f = fopen(SHMMAX_SYS_FILE, "r");
    
        if (!f) {
            fprintf(stderr, "Failed to open file: `%s'\n", SHMMAX_SYS_FILE);
            return 1;
        }
    
        if (fscanf(f, "%u", &shmmax) != 1) {
            fprintf(stderr, "Failed to read shmmax from file: `%s'\n", SHMMAX_SYS_FILE);
            fclose(f);
            return 1;
        }
    
        fclose(f);
    
        printf("shmmax: %u\n", shmmax);
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the value of div using webdriver and not Selenium For
i want to get the value of this td my code function check() {
Basically I want to get the value of a textbox which is to select
I have the follwing code. I want to get the value of the selected
i want to get value of h:outputText label using jquery, for <h:outputText id=cal_att_to_date binding=#{Attendance_Calculation.cal_att_to_date}>
I want to get value from NSDictionary . I want to control Code key
My problem is this, i want to get value of yweather->code from xml file:
I want to get sum from the list using generics as like List<Name,Value> test=new
i have this dynamic textbox, and i want to get value by using class.
I want to get value in a date picker and add to textfield_date..I used

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.