メモリ情報を調べる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Makefile | |
sysinfo: sysinfo.c | |
g++ -o sysinfo sysinfo.c | |
clean: | |
rm -f sysinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); | |
exit(EXIT_FAILURE); | |
} | |
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); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment