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

int main()
{
  int fd = open("./example.txt",O_CREAT | O_RDWR,0644);
  assert(fd != -1);
  char* file_contents = mmap(0,15ull*1024ull*1024ull*1024ull,PROT_READ | PROT_WRITE, MAP_SHARED,fd,0);
  while (1) {
    printf("> ");
    char* line = 0;
    size_t size = 0;
    getline(&line,&size,stdin);
    line[strlen(line)-1] = 0;
    printf("writing '%s'\n",line);
    ftruncate(fd,strlen(line)+1);
    while(file_contents[0] != 2);
    strcpy(file_contents+1,line);
    strcat(file_contents+1,"\n");
    file_contents[0] = 1; // the other should read!
  }
  return -1;
}