❶ 怎样使用c语言程序获取Linux系统中未使用的内存大小
可以通过调用系统命令free。
获取free命令的输出值。
比如 system("free > tmp.txt");
然后fopen打开tmp.txt 获取输出,然后处理free的结果得到未使用内存大小。
也可以直接打开/proc/meminfo
第二行MemFree后面的数字就是free内存大小。
第二种更常用一些。
❷ c语言 怎么读内存数据
分配内存空间然后读取
#include<stdio.h>
#include<stdlib.h>
intfilelength(FILE*fp);
char*readfile(char*path);
intmain(void)
{
FILE*fp;
char*string;
string=readfile("c:/c.c");
printf("读入完毕 按任意键释放内存资源 ");
//printf("%s ",string);
system("pause");
return0;
}
char*readfile(char*path)
{
FILE*fp;
intlength;
char*ch;
if((fp=fopen(path,"r"))==NULL)
{
printf("openfile%serror. ",path);
exit(0);
}
length=filelength(fp);
ch=(char*)malloc(length);
fread(ch,length,1,fp);
*(ch+length-1)='