我有以下将 infile 连接到 outfile 的简单程序
char *execArgs[] = { "cat", NULL};
int outfile = open("outfile", O_WRONLY | O_CREAT, 0644);
int infile = open("infile", O_RDONLY, 0);
dup2(outfile, STDOUT_FILENO);
dup2(infile, STDIN_FILENO);
close(outfile);
close(infile);
execvp(execArgs[0], execArgs);
现在,假设 infile 的内容是
this is infile
和outfile是
this is outfile
运行程序后,outfile的内容最后多了一个“e”,这样
this is infilee
此外,如果 outfile 是
this is outfile
this is outfile
它成为了
this is infilee
this is outfile
怎么了?