printf anomaly after “fork()”
Reference:
#include <stdio.h>
#include <unistd.h>
int main()
{
int pid;
printf( "Hello, my pid is %d", getpid() );
pid = fork();
if( pid == 0 )
printf( "I was forked! :D %d\n", getpid() );
else
{
waitpid( pid, NULL, 0 );
printf( "%d was forked!\n", pid );
}
return 0;
}
/*
OUTPUT:
Hello, my pid is 60I was forked! :D 61
Hello, my pid is 60 61 was forked!
*/