How to use perror with dup2?
问题 I'm adding error handling to my small C program and I've gotten it to work with fork and for execvp but not for dup2. int spawn_proc (int in, int out, struct command *cmd) { pid_t pid; if ((pid = fork ()) == 0) { if (in != 0) { dup2 (in, 0); close (in); } if (out != 1) { dup2 (out, 1); close (out); } if (execvp(cmd->argv [0], (char * const *)cmd->argv) < 0) { perror("execvp failed"); exit(1); } } else if (pid < 0) { perror("fork failed"); exit(1); } return pid; } How should perror be used