#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <assert.h>
#include <sys/wait.h>

char* p[110000];

int main()
{
  for (size_t i = 0; i < 110000; ++i)
  {
    p[i] = malloc(1024ull*1024ull*1024ull);
    printf("%zu GB allocated, got pointer %p now\n",i,p[i]);
    if (p[i] == NULL)
      goto error;
  }
  
  puts("let's fill the memory!\n");

  for (size_t i = 0; i < 5; ++i)
  {
    for (size_t j = 0; j < 1024ull*1024ull*1024ull; j += 128)
      p[i][j] = 37 * j;

    printf("%zu GB filled\n",i);
  }

  success:
  puts("now the system will clean up\n");
  return 0;

  error:
  puts("malloc returned 0 so we are out of memory now!\n");
  return -1;
}