Originally Posted by Anand Singh
I want to emulate dup2 without using fcntl. can anybody help me?
At a fundamental level, you can't. It is a system call that duplicates a file descriptor which is a kernel data structure. The file descriptor returned to a user process is nothing but an index into the kernel table - so "emulation" doesn't exist.