Pipes and File Descriptors
A fork’d child inherits file descriptors from its parent
It’s possible to alter these using fclose() and fopen():
fclose( stdin );
FILE *fp = fopen( “/tmp/junk”, “r” );
One could exchange two entries in the fd table by closing and reopening both streams, but there’s a more efficient way, using dup() or dup2() (…see next slide)