racing condition

#include <stdio.h>

void printn(int n, pid_t pid)
{
int c;
for (c = 0; c < n; c++)
if (pid)
printf("parent: %d
", c);
else
printf("child: %2d
", c);
}

int main(void)
{
pid_t pid;
pid = fork();
printn(5, pid);
return 0;
}

source

Leave a Reply