Skip to content

Instantly share code, notes, and snippets.

Created February 4, 2014 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/8811035 to your computer and use it in GitHub Desktop.
Save anonymous/8811035 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <signal.h>
char *memory;
void signal_handler(int signo)
{
free (memory);
exit(0);
}
size_t getTotalSystemMemory()
{
long pages = sysconf(_SC_AVPHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
return pages * page_size;
}
int main()
{
printf("System Memory: %zu\n", getTotalSystemMemory());
memory = malloc(getTotalSystemMemory()*.85);
memset(memory, 0, getTotalSystemMemory()*.85);
printf("System Memory: %zu\n", getTotalSystemMemory());
while(1)
{
if (signal(SIGINT, signal_handler) == SIG_ERR)
{
printf("Signal Error\n");
exit(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment