我在APUE看到了这段代码片段。
dup2(fd,0);
dup2(fd,1);
dup2(fd, 2);
if (fd > 2)
close(fd);
据我理解,它将stdin、stdout和stderr都指向了fd。它说很多程序都包含这个代码,为什么?它有什么功能?