~/ learn/ comp-325/ cards/ Two descriptors from one call
1 of 12

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

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/98f5e123-a00b-4fec-9cc0-29a6b4f67000/flashcard utf-8 LF