#define _GNU_SOURCE #include #include #include #include #include #include #define SIZE 1024 char* sharedMem; int parent() { sleep(1); printf("Parent: Writing...\n"); strcpy(sharedMem, "Bla bla bla\n"); munmap(sharedMem, SIZE); return 0; } int child() { sleep(3); printf("Child: Reading: "); char buffer[100]; strcpy(buffer, sharedMem); puts(buffer); munmap(sharedMem, SIZE); return 0; } int main() { sharedMem = (char*)mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); pid_t res = fork(); if (res < 0) return 1; if (res > 0) return parent(); else return child(); return 0; }