Can someone explain what dup() in C does?

前端 未结 8 1172
不知归路
不知归路 2021-01-30 23:34

I know that dup, dup2, dup3 \"create a copy of the file descriptor oldfd\"(from man pages). However I can\'t digest it.

As I know file descriptors are just

8条回答
  •  不要未来只要你来
    2021-01-30 23:45

    dup() and dup2() system call

    •The dup() system call duplicates an open file descriptor and returns the new file descriptor.

    •The new file descriptor has the following properties in common with the original file descriptor: 1. refers to the same open file or pipe. 2. has the same file pointer -- that is, both file descriptors share one file pointer. 3. has the same access mode, whether read, write, or read and write.

    • dup() is guaranteed to return a file descriptor with the lowest integer value available.It is because of this feature of returning the lowest unused file descriptor available that processes accomplish I/O redirection.

    int dup(file_descriptor)

    int dup2(file_descriptor1, file_descriptor2)

提交回复
热议问题