Create the pipe and check it
Create the pipe and check it
Answer
int pipefd[2]; if (pipe(pipefd) == -1) { perror("pipe"); _exit(1); } printf("read end %d, write end %d\n", pipefd[0], pipefd[1]);
pipe() returns 0 or -1, so the == -1 test is the mandatory error check (EMFILE, ENFILE, ENOMEM). Run this in a fresh program and it prints 3 and 4: descriptors 0, 1 and 2 are already spoken for.
S&K 3e ch20 §20.3, §20.4.2; pipe() per POSIX.1-2024