LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-18-2009, 04:24 PM   #1
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,229

Rep: Reputation: 173Reputation: 173
test how much mem the operating system has free in C


with GNU CC how do i test how much memory is free to the entire operating system ?
old turbo C++ has coreleft() but GCC does not have it
 
Old 10-18-2009, 05:05 PM   #2
verdeboy2k
Member
 
Registered: Jan 2004
Location: /dev/random
Distribution: Gentoo amd64, CrunchBang amd64
Posts: 350

Rep: Reputation: 32
sysinfo() can do that:

Code:
#include <sys/sysinfo.h>

int main() {
     struct sysinfo info;

     sysinfo(&info);

     printf("RAM: %d\n",info.totalram);

     return 0;
}
For more information:
Code:
man sysinfo
This is linux specific, I don't know how to do this on other platforms. There is no GCC or ISO C specific call for this that I know of.

Last edited by verdeboy2k; 10-18-2009 at 05:06 PM. Reason: Forgot to mention that this is Linux Specific
 
Old 10-18-2009, 05:51 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,229

Original Poster
Rep: Reputation: 173Reputation: 173
need cross platform
 
Old 10-18-2009, 06:16 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 58
Quote:
Originally Posted by smeezekitty View Post
need cross platform
a "thanks for trying" would have been nice.

as verdeboy2k said, and i agree with, i dont think there is a cross-platform GNU C API to do this, as it relies heavily on the OS.
 
Old 10-18-2009, 06:17 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,229

Original Poster
Rep: Reputation: 173Reputation: 173
how about a library?
 
Old 10-18-2009, 06:21 PM   #6
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 58
there are a number of ways to do it in linux, one of them mentioned above, and a simple search will give you the windows API to do it. i dont know of any library that wraps them all to make it seem cross-platform
 
Old 10-18-2009, 06:23 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,229

Original Poster
Rep: Reputation: 173Reputation: 173
ok then, i will write a library
one question is -- what windows API will give you the same info
 
Old 10-18-2009, 06:32 PM   #8
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu
Posts: 2,539

Rep: Reputation: 58
regarding the library, a search gave a forum which referenced this: http://code.google.com/p/geekinfo/. the description seems to be what you want, though i didnt look at any other details.

i dont remember the exact windows API one (im sure after some searching MSDN you will find it), but a good starting point is here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
 
  


Reply

Tags
cc, free, gcc, gnu, mem, memory


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'Operating system not found' Any operating system installed wont work. TechniSlave Linux - Newbie 55 02-09-2009 11:02 AM
Is it a free operating system? Marty21 Solaris / OpenSolaris 16 02-03-2009 05:16 AM
I'm on the sidewalks, and need a free Operating System SidewalkCynic LinuxQuestions.org Member Intro 19 03-22-2008 01:13 PM
Linspire 4.5 Operating System Free at Linspire.com shmude Linspire/Freespire 9 11-13-2004 05:47 PM
How to change kernel's system/user mem ratio? marvin Linux - General 2 03-07-2003 07:11 AM


All times are GMT -5. The time now is 07:04 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration