I am redirecting stdout on a process with freopen(), and as long as it's just one process, everything's fine.
However, if I do something like this:
freopen("stdout.txt", "a+", stdout);
printf("Initial line.\n");
int i=0;
while(i<1000)
{
if(fork())
wait(NULL);
else
printf("Line %d.\n", i);
i++;
}
The first printed lines are re-printed on the file over and over. Is there anything particular I should do to avoid this from happening?