LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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

Tags used in this thread
Popular LQ Tags , , , , ,

Reply
 
Thread Tools
Old 10-18-2009, 05:24 PM   #1
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,233
Thanked: 59
test how much mem the operating system has free in C


[Log in to get rid of this advertisement]
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
windows_vista smeezekitty is offline  
Tag This Post , , , , ,
Reply With Quote
Old 10-18-2009, 06:05 PM   #2
verdeboy2k
Member
 
Registered: Jan 2004
Location: /dev/random
Distribution: Gentoo amd64, CrunchBang amd64
Posts: 338
Thanked: 2
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 06:06 PM.. Reason: Forgot to mention that this is Linux Specific
linuxgentoo verdeboy2k is offline     Reply With Quote
Old 10-18-2009, 06:51 PM   #3
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,233
Thanked: 59

Original Poster
need cross platform
windows_vista smeezekitty is offline     Reply With Quote
Old 10-18-2009, 07:16 PM   #4
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu, windows xp
Posts: 2,429
Thanked: 10
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.
linuxfedora nadroj is offline     Reply With Quote
Old 10-18-2009, 07:17 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,233
Thanked: 59

Original Poster
how about a library?
windows_vista smeezekitty is offline     Reply With Quote
Old 10-18-2009, 07:21 PM   #6
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu, windows xp
Posts: 2,429
Thanked: 10
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
linuxfedora nadroj is offline     Reply With Quote
Thanked by:
Old 10-18-2009, 07:23 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,233
Thanked: 59

Original Poster
ok then, i will write a library
one question is -- what windows API will give you the same info
windows_vista smeezekitty is offline     Reply With Quote
Old 10-18-2009, 07:32 PM   #8
nadroj
Senior Member
 
Registered: Jan 2005
Location: Canada
Distribution: ubuntu, windows xp
Posts: 2,429
Thanked: 10
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
linuxfedora nadroj is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 12:02 PM
Is it a free operating system? Marty21 Solaris / OpenSolaris 16 02-03-2009 06:16 AM
I'm on the sidewalks, and need a free Operating System SidewalkCynic LinuxQuestions.org Member Intro 19 03-22-2008 02:13 PM
Linspire 4.5 Operating System Free at Linspire.com shmude Linspire/Freespire 9 11-13-2004 06:47 PM
How to change kernel's system/user mem ratio? marvin Linux - General 2 03-07-2003 08:11 AM


All times are GMT -5. The time now is 10:48 PM.

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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration