DUP and dup2 Functions

Source: Internet
Author: User

DUP and dup2 Functions

Function prototype:

Int DUP (int fd)

Int dup2 (INT oldfd, int newfd)

The DUP and dup2 functions can copy file descriptors.

1. DUP

DUP copies the file descriptor FD and returns the new descriptor, which points to the same file. The new descriptor is the smallest available file descriptor in the system.

2. dup2
Dup2 copies the file descriptor oldfd and can specify newfd as the new descriptor value. If newfd has already pointed to a file, disable it first, and then

File descriptors replicated by the DUP and dup2 functions share all file identifiers except the fd_cloexec identifiers.

Return Value:
A new file descriptor is returned. If the file descriptor fails,-1 is returned;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.