#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/kernel.h>
static int print_memory_size(void)
{
int errorCode = 0;
struct sysinfo si;
errorCode = sysinfo(&si);
if (errorCode) {
printf("Failed to get memory type: %d \n", errorCode);
return -1;
}
printf("Total memory : %ld KB\n", (si.totalram / 1024));
return 0;
}
void main(void)
{
print_memory_size();
}
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <linux/kernel.h>
static int print_memory_size(void)
{
int errorCode = 0;
struct sysinfo si;
errorCode = sysinfo(&si);
if (errorCode) {
printf("Failed to get memory type: %d \n", errorCode);
return -1;
}
printf("Total memory : %ld KB\n", (si.totalram / 1024));
return 0;
}
void main(void)
{
print_memory_size();
}

本文介绍了一个简单的C程序,用于获取并打印系统的总内存大小。通过调用sysinfo函数,程序能够检索到系统的内存信息,并将其转换为KB单位进行展示。
2万+

被折叠的 条评论
为什么被折叠?



