man pages section 2: System Calls
  Search only this book
Download this book in PDF (1785 KB)

dup(2)

Name | Synopsis | Description | Return Values | Errors | Attributes | See Also

Name

    dup– duplicate an open file descriptor

Synopsis

    #include <unistd.h>
    
    int dup(int fildes);

Description

    The dup() function returns a new file descriptor having the following in common with the original open file descriptor fildes:

    • same open file (or pipe)

    • same file pointer (that is, both file descriptors share one file pointer)

    • same access mode (read, write or read/write).

    The new file descriptor is set to remain open across exec functions (see fcntl(2)).

    The file descriptor returned is the lowest one available.

    The dup(fildes) function call is equivalent to:

    fcntl(fildes, F_DUPFD, 0)

Return Values

    Upon successful completion, a non-negative integer representing the file descriptor is returned. Otherwise, -1 is returned and errno is set to indicate the error.

Errors

    The dup() function will fail if:

    EBADF

    The fildes argument is not a valid open file descriptor.

    EINTR

    A signal was caught during the execution of the dup() function.

    EMFILE

    The process has too many open files (see getrlimit(2)).

    ENOLINK

    The fildes argument is on a remote machine and the link to that machine is no longer active.

Attributes

    See attributes(5) for descriptions of the following attributes:

    ATTRIBUTE TYPE 

    ATTRIBUTE VALUE 

    Interface Stability 

    Standard 

    MT-Level 

    Async-Signal-Safe 

See Also

SunOS 5.11  Last Revised 28 Dec 1996

Name | Synopsis | Description | Return Values | Errors | Attributes | See Also