dup2(int oldfd, int newfd);
This is an equivalent of:
By closing "newfd" first, it becomes the lowest-numbered unused file descriptor (normally). Because of that the oldfd is copied to newfd (dup system call). So far, everything is clear.
Now see: http://codewiki.wikidot.com/c:system-calls:dup2
dup2 is a system call similar to dup in that it duplicates one file descriptor, making them aliases, and then deleting the old file descriptor.
Actually I don't think the old file descriptor will be deleted?
After a successful return, the old and new file descriptors may be used interchangeably.
If the old file descriptor will be deleted, then they would not say something like that. Is wikidot.com just wrong about this?