C & Unix

dup2, Redirection and Unix Pipelines

8:08

Plays from YouTube. Watch on YouTube

How does a shell connect two programs that never knew about each other?

Meet dup2, Redirection and Unix Pipelines: an original animated lesson in C and Unix systems programming.

We start with stdin, stdout and stderr, then show how dup2 duplicates a reference into a chosen descriptor number.

From there, we build a pipeline using pipe, fork, dup2, close and exec, and examine multistage pipelines and redirection errors.

The big idea: The shell constructs descriptor connections while programs keep using ordinary read and write interfaces.

C and Unix explained visually, one concept at a time.