Can someone explain what dup() in C does?

前端 未结 8 1083
不知归路
不知归路 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-31 00:06

    Just a tip about "duplicating standard output".

    On some Unix Systems (but not GNU/Linux)

    fd = open("/dev/fd/1", O_WRONLY);
    

    it is equivalent to:

    fd = dup(1);
    

提交回复
热议问题