Last active
July 17, 2020 05:59
-
-
Save tuaris/5004602f9c3c52500260ba6cd0a4c9a9 to your computer and use it in GitHub Desktop.
Small C program to get total physical RAM in FreeBSD
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
#include <sys/types.h> | |
#include <sys/sysctl.h> | |
#include <stdio.h> | |
uint64_t | |
get_mem_size() | |
{ | |
uint64_t memsize = -1; | |
size_t len = sizeof(memsize); | |
int name[] = {CTL_HW, HW_PHYSMEM}; | |
sysctl(name, 2, &memsize, &len, NULL, 0); | |
return memsize; | |
} | |
int main() | |
{ | |
uint64_t mem; | |
mem = get_mem_size(); | |
printf("mem = %lu\n", mem); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile and run on FreeBSD