~/ 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/318c561c-5caf-4e3f-be99-dbe7dd3e6c12/flashcard utf-8 LF