#include #include #include int main(int argc, char** argv) { char* buffer = malloc(100); strcpy(buffer, "Hello World\n"); int pid = fork(); if (pid < 0) { fprintf(stderr, "fork failed\n"); exit(1); } else if (pid == 0) { fprintf(stderr, "child process "); fprintf(stderr, "%s", buffer); } else { fprintf(stderr, "forked process %d ", pid); fprintf(stderr, "%s", buffer); } /* both parent and child have their own copy of buffer and need to free it */ free(buffer); return 0; }