Fork() function in C - Stack Overflow
https://stackoverflow.com/questions/32810981/fork-function-in-c
int main() {
puts("Setting up buffer...");
setbuf(stdout, NULL);
puts("Setting up pointers...");
counter = malloc(sizeof(*counter));
who = malloc(sizeof(*who));
*counter = 0;
*who = 1;
puts("Running...");
if (fork() == 0) {
puts("Hi, I am the child!");
while (1) {
while (*who != 0);
(*counter)++;
*who = 1;
printf("*%lld = %d\n", counter, *counter);
}
}
{
puts("I am the parent.");
while (1) {
while (*who != 1);
(*counter)++;
*who = 0;
printf("*%lld = %d\n", counter, *counter);
}
}
}
Still not woking. :-/