•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,383 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 2320 | Replies: 5
![]() |
•
•
Join Date: Aug 2006
Posts: 29
Reputation:
Rep Power: 2
Solved Threads: 1
Can anybody please tell me how to calculate/find total remaining(unused/free) memory in the system(using any functions)? Thanks Iqbal
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation:
Rep Power: 36
Solved Threads: 867
Assuming you mean MS-Windows operating system, call GlobalMemoryStatus.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation:
Rep Power: 36
Solved Threads: 867
•
•
Join Date: May 2004
Posts: 177
Reputation:
Rep Power: 5
Solved Threads: 9
cat /proc/meminfo
You could also just read /proc/meminfo (read only) as a regular file and find the value using C only.
snippet:
#include <stdio.h>
void foo(void)
{
char *cmd="awk '{ if(NR==2){print $4}}' /proc/meminfo";
FILE *cmdfile=popen(cmd,"r");
char result[256]={0x0};
while(fgets(result,sizeof(result),cmdfile)!=NULL)
{
printf("%s\n",result);
}
pclose(cmdfile);
}
•
•
Join Date: Aug 2006
Posts: 29
Reputation:
Rep Power: 2
Solved Threads: 1
•
•
•
•
shows the current state of memory. The format varies somewhat with Linux distributions. My version of Linux has what you want in the 4 th column on the second line. So, you will need to get the awk statement working for you. Then put it in the C code.cat /proc/meminfo
You could also just read /proc/meminfo (read only) as a regular file and find the value using C only.
snippet:
#include <stdio.h> void foo(void) { char *cmd="awk '{ if(NR==2){print $4}}' /proc/meminfo"; FILE *cmdfile=popen(cmd,"r"); char result[256]={0x0}; while(fgets(result,sizeof(result),cmdfile)!=NULL) { printf("%s\n",result); } pclose(cmdfile); }
Thank you very much Jim. It is really a great help.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Other Threads in the C Forum
- Previous Thread: Class Project
- Next Thread: Pointer tutor



Linear Mode