I'm writing a program in C++ for linux platform. The program uses fork() to run a certain task as a child process.
When I place printf() calls in the child process, that output never shows up anywhere. From everything I've found on the web, it seems that stdin and stdout are supposed to work the same in the child process as in the parent, and the child should inherit the parent's stdin, stdout, and stderr. Doesn't printf go to stdout by default? I've found that I can output messages using sprinf() / write(STDOUT_FILENO,...), but this is somewhat inconvenient. More importantly, it's a sign that there's something I'm not getting about how this is supposed to work.
Where is the printf output is going, and how would I make it work from within a child process? (I'm a veteran programmer, but new to linux.)
if (fork() == 0)
// In child process
printf( "This message goes nowhere\n");
char buf = "This message goes to the console\n";
write( STDOUT_FILENO, buf, strlen(buf));