According to my understanding of fork()
, this should print "Hello, World!" once, since there is only one process before fork
is called. However, it prints twice. Curiously, if I add a \n
to the string or use puts()
instead of printf()
, it only prints once.
#include<unistd.h>
#include<stdio.h>
int main() {
printf("Hello, World!");
fork();
}