Pipe function in Linux shell write in C
问题 My mini-shell program accepts pipe command, for example, ls -l | wc -l and uses excevp to execute these commands. My problem is if there is no fork() for execvp, the pipe command works well but the shell terminates afterward. If there is a fork() for execvp, dead loop happens. And I cannot fix it. code: void run_pipe(char **args){ int ps[2]; pipe(ps); pid_t pid = fork(); pid_t child_pid; int child_status; if(pid == 0){ // child process close(1); close(ps[0]); dup2(ps[1], 1); //e.g. cmd[0] =