What is the relation between dup() and close() system calls?

Viewed 1038

I've searched this topic on web and came across this explain but I can not get the idea behind of it. Code and explanation is as follows..

#include <unistd.h>
...
int pfd;
...
close(1);
dup(pfd);
close(pfd); //** LINE F **//
...

/*The example above closes standard output for the current
processes,re-assigns standard output to go to the file referenced by pfd,
and closes the original file descriptor to clean up.*/

What does LINE F do? Why it is crucial?

1 Answers
Related