dup

DUP(2)                     Linux Programmer's Manual                    DUP(2)



åå
       dup, dup2 - ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ãè¤è£½ãã

æ¸å¼
       #include <unistd.h>

       int dup(int oldfd);
       int dup2(int oldfd, int newfd);

説æ
       dup 㨠dup2 ã¯ããã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ oldfd ã®è¤è£½ãä½ãã

       å¤ããã£ã¹ã¯ãªãã¿ã¼ã¨æ°ãããã£ã¹ã¯ãªãã¿ã¼ã¯åããã®ã¨ã㦠使ããã¨ãã§ããã ãããã¯ã‐
       ãã¯(lock)ããã¡ã¤ã«ä½ç½®ãã¤ã³ã¿ã¼ã ãã©ã°ãå±æããã
       ä¾ãã°ãçæ¹ã®ãã£ã¹ã¯ãªãã¿ã¼ã® ãã¡ã¤ã«ä½ç½®ã lseek
       使ç¨ãã¦å¤æ´ãããå ´åããããçæ¹ã®ä½ç½®ãå¤åããã
       ããããªããããµãã¤ã®ãã£ã¹ã¯ãªãã¿ã¼ã¯å®è¡æã¯ãã¼ãº(close-on-exec)
       ãã©ã°ãå±æãã¦ããªãã

       dup ã¯ä½¿ç¨ããã¦ããªãæå°ã®å¤ã®ãã£ã¹ã¯ãªãã¿ã¼ãæ°ãããã£ã¹ã¯ãªãã¿ã¼
       ã¨ãã¦ä½¿ç¨ããã

       dup2 㯠oldfd ã®è¤è£½ã¨ã㦠newfd ãä½æãããå¿è¦ãªãã°æåã« newfd ãã¯ã‐
       ã¼ãº(close)ããã

è¿ãå¤
       dup 㨠dup2 ã¯æ°ãããã£ã¹ã¯ãªãã¿ã¼ãè¿ããã¨ã©ã¼ã®å ´å㯠-1 ãè¿ãã (ãã®æã
       errno ã«é©åãªå¤ãè¨å®ãããã)

ã¨ã©ã¼
       EBADF  oldfd ããªã¼ãã³ããããã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ã§ãªããã newfd
              ããã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ã¨ãã¦è¨±ãããç¯å²ããå¤ãã¦ããã

       EMFILE ããã»ã¹ããã§ã«ãªã¼ãã³ã§ããæ大æ°ã¾ã§ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼
              ãéãã¦ãã¦ãããã«æ°ãããã®ãéããã¨ããã

è¦å
       newfd ãç¯å²ãè¶ããæã«è¿ãããã¨ã©ã¼ã¯ã dup2 㨠fcntl(...,F_DUPFD,...)
       ã§ã¯ç°ã£ã¦ããã dup2 ã F_DUPFD ã¨åãããã« EINVAL ãè¿ãã¹ãã ãããã

æºæ
       SVr4, SVID, POSIX, X/OPEN, BSD 4.3. SVr4 ã«ã¯ä»ã« EINTR,ENOLINK
       ã¨ã©ã¼ç¶æã®è¨è¿°ããããPOSIX.1 ã«ã¯ä»ã« EINTR ãããã

é¢é£é ç®
        fcntl (2), open (2), close (2).



Linux 1.1.46                    21 August 1994                          DUP(2)