0
我在c中實現shell時做了這個,但雖然在實現管道時,我想出了這個錯誤ls:write error:Bad file描述符,我不明白爲什麼這個錯誤即將到來, 請幫助。管道實現中的錯誤,我面臨這個錯誤,ls:寫入錯誤:錯誤的文件描述符
#include<stdio.h>
#include<unistd.h>
#include <stdlib.h>
void execute(char **argv)
{
pid_t pid;
int status;
//fflush(0);
pid_t id ;
int out=0,in=0,pip=0;
int fds[2];
if ((pid = fork()) < 0) { /* fork a child process */
printf("*** ERROR: forking child process failed\n");
exit(1);
}
if (pid==0) {
close(1); /* close normal stdout */
dup2(fds[1],1); /* make stdout same as pfds[1] */
close(fds[0]); /* we don't need this */
execlp(argv[0],argv[0],argv[1],NULL);
}
else {
close(0); /* close normal stdin */
dup2(fds[0],0); /* make stdin same as pfds[0] */
close(fds[1]); /* we don't need this */
execlp(argv[3],argv[3],argv[4], NULL);
}
}
耶得到了僅管()調用失蹤感謝 –