What do the dup() and dup2() system calls really do? How would I use them in practice?
What do the dup() and dup2() system calls really do? How would I use
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Both make a new file descriptor corresponding to an existing open file description. Most properties between the old and new fd (like position) are shared; the only property I can think of that’s not shared is the close-on-exec flag. The difference between
dupanddup2is thatdupassigns the lowest available file descriptor number, whiledup2lets you choose the file descriptor number that will be assigned and atomically closes and replaces it if it’s already taken.