2
0

dup.c 404 B

123456789101112131415161718
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. int main(void) {
  6. creat("dup.out", 0777);
  7. int fd1 = open("dup.out", 0);
  8. int fd2 = dup(fd1);
  9. printf("fd %d duped into fd %d\n", fd1, fd2);
  10. close(fd1);
  11. close(fd2);
  12. int fd3 = open("dup.out", 0x0002, 0x1000);
  13. dup2(fd3, 1);
  14. printf("hello fd %d", fd3);
  15. close(fd3);
  16. return EXIT_SUCCESS;
  17. }