pipe()¶
Purpose¶
pipe() creates a unidirectional byte-stream channel with two file descriptors.
It is useful for simple parent-child communication and for building fd-based event examples.
Header¶
Prototype¶
Parameters¶
| Parameter | Description |
|---|---|
pipefd[0] |
Read end of the pipe. |
pipefd[1] |
Write end of the pipe. |
Return Value¶
Returns 0 on success. Returns -1 on failure and sets errno.
Minimal Example¶
Common Pitfalls¶
- Not closing unused ends after
fork(). - Expecting message boundaries; pipes are byte streams.
- Not handling
EPIPEwhen the read end is closed. - Forgetting that pipe capacity is finite.