PIPE(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

πŸ’– PIPE(3) β€” Library Functions Manual πŸ’–

okay bestie, welcome to the pipe page, this is PIPE(3) from the Library Functions Manual and honestly it's giving "small function, chaotic lore" energy so let's get into it 🫢


✨ NAME ✨

pipe β€” create an interprocess channel πŸ’…


🌸 SYNOPSIS 🌸

#include <u.h>
#include <libc.h>

int pipe(int fd[2])

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so Pipe creates a buffered channel for interprocess I/O communication ✨. That's the whole vibe. Two file descriptors come back to you inside fd β€” literally two, no more no less, it's a duo πŸ’….

And here's the cute part: data written to fd[1] is available for reading from fd[0], and data written to fd[0] is available for reading from fd[1]. It goes both ways bestie, it's mutual 🌈.

Once the pipe is established, cooperating processes created by subsequent fork(2) calls may pass data through the pipe with read and write calls. group chat, but for processes, no cap πŸŽ€

When all the data has been read from a pipe and the writer has closed the pipe or exited, read(3) will return 0 bytes β€” that's the "they left the chat" signal, iconic πŸ’€.

⚠️ Writes to a pipe with no reader will generate a note sys: write on closed pipe. like yelling into a void, but the void files a complaint 😭

🧚 SOURCE 🧚

/src/lib9/pipe.c

⭐ SEE ALSO ⭐

(iykyk, go read them, they're literally connected πŸ’œ)


πŸŽ€ DIAGNOSTICS πŸŽ€

Sets errstr. that's it, that's the diagnostic, she's efficient πŸ¦‹


πŸ’€ BUGS πŸ’€

okay this section is a lot, buckle up:

  • If a read or a write of a pipe is interrupted, some unknown number of bytes may have been transferred. like, unknown unknown. we don't know. nobody knows. πŸ™ˆ
  • Pipe is a macro defined as p9pipe to avoid name conflicts with Unix's pipe system call. it's a nickname situation πŸ‘‘
  • Unix pipes are not guaranteed to be bidirectional. In order to ensure a bidirectional channel, p9pipe creates Unix domain sockets via the socketpair(2) instead of Unix pipes. so she's not even a pipe pipe, she's a socket in a trench coat πŸ§₯✨
  • The implementation of pipes as Unix domain sockets causes problems with some Unix implementations of /dev/fd, Unix's dup device. If a Unix domain socket is open as file descriptor 0, some implementations disallow the opening of /dev/fd/0; instead one must connect(2) to it. the audacity honestly 😀
  • If this functionality is important (as it is for rc(1)), one must #undef pipe and fall back on the (possibly unidirectional) Unix pipes. so you gotta let go of the good version to get the compatible version, we've all been there πŸ’…

🌸 that's the whole page bestie, go make some channels 🌸

πŸ’– from PIPE(3), Library Functions Manual, footer says PIPE(3) and like, that's the version and date situation β€” signed off with love, xoxo πŸŽ€πŸ«Ά