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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:21:49+00:00 2026-05-28T08:21:49+00:00

I recently wrote the following C code using sysinfo systemcall to display system statistics,

  • 0

I recently wrote the following C code using sysinfo systemcall to display system statistics, what amused me was that the freeram variable of sysinfo structure doesn’t return the amount of free RAM instead it is returning the current RAM usage. I had to use a workaround to show the correct value by subtracting freeram from totalram. I have tried googling about this specific variable but to no avail. Any insight into this weird behavior would be really helpful.

/*
 * C program to print the system statistics like system uptime, 
 * total RAM space, free RAM space, process count, page size
 */

#include <sys/sysinfo.h>    // sysinfo
#include <stdio.h>
#include <unistd.h>     // sysconf
#include "syscalls.h"       // just contains a wrapper function - error

int main()
{
    struct sysinfo info;

    if (sysinfo(&info) != 0)
        error("sysinfo: error reading system statistics");

    printf("Uptime: %ld:%ld:%ld\n", info.uptime/3600, info.uptime%3600/60, info.uptime%60);
    printf("Total RAM: %ld MB\n", info.totalram/1024/1024);
    printf("Free RAM: %ld MB\n", (info.totalram-info.freeram)/1024/1024);
    printf("Process count: %d\n", info.procs);
    printf("Page size: %ld bytes\n", sysconf(_SC_PAGESIZE));

    return 0;
}
  • 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-28T08:21:49+00:00Added an answer on May 28, 2026 at 8:21 am

    Remove

    #include "syscalls.h"
    

    May be, you borrowed the code from somewhere and edited. Double quotes are used to import unofficial header files. That custom header file is not really required.

    It’s not needed. You code will run fine.

    On my PC, freeram value of $free -m matches with info.freeram of the program. Apparently, freeram is not what you think it’s showing.

    Read more about the http://www.redhat.com/advice/tips/meminfo.html

    MemFree is the free memory & MemFree + Buffers + Cached is available memory (which you want). So, you are just understanding the term freeram wrongly.

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

Sidebar

Related Questions

I recently wrote some javascript code that filled a drop down list based on
I have recently created a new rails 3 application, using the code that I
Recently, after being very tired, I wrote the following code: GLfloat* array = new
I recently wrote a parser in Python using Ply (it's a python reimplementation of
I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I recently wrote a piece of code which did SomeClass someObject; mysqlpp::StoreQueryResult result =
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I recently wrote some data access methods (plain old Java) that use immutable objects
We have a recently internationalised application written in classic ASP. The following code replicates
I have an app that I wrote using C# .NET 4.0 in Visual Studio

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.