clone

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



åå
       clone - åããã»ã¹ãä½ã

æ¸å¼
       #include <linux/sched.h>
       #include <linux/unistd.h>

       pid_t clone(void *sp, unsigned long flags)

説æ
       clone 㯠fork ã®ããã®å¥ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ãããå¤ãã®ãªãã·ã§ã³ãæã¤ã fork ã¯
       clone(0, SIGCLD|COPYVM) ã«çããã

       sp ãã¼ãã§ãªãã°ãåããã»ã¹(chile process)㯠sp
       ãåæã¹ã¿ãã¯ã»ãã¤ã³ã¿ã¼ã¨ãã¦ä½¿ç¨ããã

       flags ã®ä¸ä½ãã¤ãã¯åããã»ã¹ãæ»ãã å ´åã«è¦ª(parent)ã«éãã¹ã
       ã·ã°ãã«(signal)ãå«ãã§ããã flags 㯠COPYVM 㨠COPYFD
       ã®ã©ã¡ãããã¾ãã¯ä¸¡æ¹ã¨ã® ãããOR ã§ãããã

       COPYVM ãè¨å®ãããã¨ãåãã¼ã¸(child page) ã¯è¦ªãã¼ã¸(parent page)ã®
       æ¸ãè¾¼ã¿ã®ããã®ã³ã¼ãã¼(copy-on-write)ã¤ã¡ã¼ã¸ã«ãªãã COPYVM ãè¨‐
       å®ããã¦ããªããã°ãåããã»ã¹ã¯è¦ªã¨åããã¼ã¸ãå±æãã å‐
       ã¨è¦ªã¯åããã¼ã¿ã«æ¸ãè¾¼ããã¨ãã§ããã

       COPYFD ãè¨å®ãããã¨ãåã®ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼(file descriptor)ã¯
       親ã®ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ã®ã³ãã¼ã«ãªãã COPYFD ãè¨å®ããã¦ããªããã°ãå‐
       ã®ãã¡ã¤ã«ã»ãã£ã¹ã¯ãªãã¿ã¼ã¯è¦ªã¨ å±æãããã

è¿ãå¤
       æåããå ´åã親ã®å®è¡ã¹ã¬ãã(thread of execution)ã«ã¯åããã»ã¹ã® PID ãè¿ãããå‐
       ã®å®è¡ã¹ã¬ããã«ã¯ 0 ãè¿ãããã失æããå ´åã«ã¯ 親㫠-1 ãè¿ãããåããã»ã¹ã¯ä½ãããã
       errno ãé©åã«è¨å®ãããã

ã¨ã©ã¼
       EAGAIN fork
              ã§è¦ªã®ãã¼ã¸ã»ãã¼ãã«ãã³ãã¼ããã®ã«ååãªã¡ã¢ãªã¼ã確ä¿ã§ããªãã£ãã å‐
              ã®ããã®ã¿ã¹ã¯æ§é ä½(task structure)ã確ä¿ã§ããªãã£ãã

ãã°
       ãã®ããã¥ã¢ã«ãã¼ã¸ã¯ãé常ã«å¤ããã®ã§ãããæ£ç¢ºãªæå ±ãå¾ãããã«ã¯ã
       å¥ãªæå ±æºãããã£ã¦æ¬²ããã

æºæ
       ãã®ã³ã¼ã«ã¯ Linux ç¹æã§ããã移æ¤ãæå³ããããã°ã©ã ã§ä½¿ç¨ãã¦ã¯ãããªãã

é¢é£é ç®
       fork(2)



Linux 1.2.9                      10 June 1995                         CLONE(2)