Skip to content

Instantly share code, notes, and snippets.

@tuaris
Last active July 17, 2020 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuaris/5004602f9c3c52500260ba6cd0a4c9a9 to your computer and use it in GitHub Desktop.
Save tuaris/5004602f9c3c52500260ba6cd0a4c9a9 to your computer and use it in GitHub Desktop.
Small C program to get total physical RAM in FreeBSD
#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;
}
@tuaris
Copy link
Author

tuaris commented Jul 17, 2020

Compile and run on FreeBSD

cc get_mem_size.c
./a.out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment