Pipes, Forks, and Zombies

· coding · Source ↗

TLDR

  • Harvard CS 61 (2017) lecture notes covering Unix pipe internals, SIGPIPE behavior, zombie processes, and a pipe-based waitpid alternative.

Key Takeaways

  • McIlroy proposed pipes in 1964; his 6-line shell solution to Knuth’s text-parsing problem illustrates pipes over algorithmic complexity.
  • SIGPIPE kills a writer when no readers remain – this is why seq stops running when piped to less and the screen fills.
  • Pipes can substitute for waitpid: close the write end in the parent, then read blocks until the child exits and all write ends close.
  • Zombie processes accumulate when a parent never calls waitpid; manyfork without root hits ~3400 forks, with root ~6890, before OS limits cut it off.
  • Orphaned children are reparented to init (pid 1), which calls waitpid to reclaim their process structures.

Hacker News Comment Review

  • No substantive HN discussion yet.

Original | Discuss on HN