Can we use a reading file descriptor as the first argument and writing file descriptor as second argument in a call to dup2(), so that the the output from the second file descriptor is redirected to the first one.
No. dup2
closes the second file descriptor if it's open. It doesn't hook the two file descriptors together.
You might be able to use the sendfile
or splice
system calls to copy the data on Linux, or sendfile
on OS X, without moving it through your process address space. However, these calls don't magically copy all the data without blocking your process.