这是我的代码的简短版本:
FILE *fd = tmpfile();
pid_t child_pid = fork();
if (child_pid == 0){
dup2(fileno(fd), 1);
std::cout<<"FIRST WRITE"<<std::endl;
}else{ // we are in main thread
waitpid(child_pid, &status, 0);
std::cout<<"SECOND WRITE"<<std::endl;
}
我的问题是:
fd
,对吧?谢谢!