Skip to content

Instantly share code, notes, and snippets.

Created Feb 1, 2015
What would you like to do?
# Makefile
sysinfo: sysinfo.c
g++ -o sysinfo sysinfo.c
rm -f sysinfo
// sysinfo.c
// メモリ情報を調べる
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/sysinfo.h>
int main(int argc, char *argv[])
int ret = 0;
struct sysinfo info = {0};
ret = sysinfo(&info);
if (ret != 0) {
printf("Error: sysinfo() %s\n", strerror(errno));
printf("uptime: %ld\n", info.uptime);
printf("1 minute load averages: %lu\n", info.loads[0]);
printf("5 minute load averages: %lu\n", info.loads[1]);
printf("15 minute load averages: %lu\n", info.loads[2]);
printf("totalram: %lu\n", info.totalram);
printf("freeram: %lu\n", info.freeram);
printf("sharedram: %lu\n", info.sharedram);
printf("bufferram: %lu\n", info.bufferram);
printf("totalswap: %lu\n", info.totalswap);
printf("freeswap: %lu\n", info.freeswap);
printf("procs: %d\n", info.procs);
printf("totalhigh: %lu\n", info.totalhigh);
printf("freehigh: %lu\n", info.freehigh);
printf("mem_unit: %d\n", info.mem_unit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment