親ããã»ã¹ã¯2度æ»ã¬ - ãã¼ã¢ã³åã«ä½¿ãããã«forkã®è¬
ãã¼ã¢ã³ããã»ã¹ãä½ãå ´åã«ã¯ï¼æç§æ¸ã«ããæ¸ããã¦ãã2度forkã¯ä¸è¦ã§ã¯ãªãã? ã¨ãããã¨ã以åã®è¨äºã«æ¸ããï¼
確ãã«BSDã®daemon(3) ã®ã³ã¼ãã§ã¯ï¼forkã¯1åããå¼ãã§ããªãï¼
ããã£ã¨ãã¬ã»ã¹ãã»ãã·ã§ã³ãªã¼ãã ã¨ä¸é½åãããã®ã ããï¼ã§ããªã?ã ã¨ããã®ãopen questionã ã£ãï¼
ããã«å¯¾ããçããã詳解UNIXããã°ã©ãã³ã°ã[1] ã«è¦ã¤ããï¼
SVR4ã«ããã¦ã¯ï¼ãã®æç¹ã§forkãå度å¼ã³ï¼è¦ªãçµäºãããã¨ãå§ãã人ãããï¼
2çªç®ã®åããã¼ã¢ã³ã¨ãã¦åä½ããï¼ããã¯ï¼ãã¼ã¢ã³ã¯ã»ãã·ã§ã³ãªã¼ãã§ã¯ãªãï¼
SVR4ã®è¦å (9.6ç¯) ããï¼ã»ãã·ã§ã³ãªã¼ãã§ãªããã°å¶å¾¡ç«¯æ«ãåå¾ã§ããªãï¼ã¨ãããã¨ãä¿è¨¼ããï¼
ãããã¯ï¼å¶å¾¡ç«¯æ«ãåå¾ããªããã¨ã確å®ã«ããã«ã¯ï¼ç«¯æ«è£ ç½®ããªã¼ãã³ãã度ã«O_NOCTTYãæå®ããï¼
([1] p.403)
SVR4ã®è¦åã£ã¦ãªãã ?
SVR4ã§ã¯ï¼å¶å¾¡ç«¯æ«ãå²ãä»ãããã¦ããªãã»ãã·ã§ã³ã«ããã¦ï¼
ã»ãã·ã§ã³ãªã¼ããæåã®ç«¯æ«è£ ç½®ããªã¼ãã³ããã¨ãã«ï¼ã»ãã·ã§ã³ã«å¶å¾¡ç«¯æ«ãå²ãä»ããï¼
ããã¯ï¼ã»ãã·ã§ã³ãªã¼ããopenãå¼ã¶éï¼O_NOCTTYãã©ã° (3.3ç¯) ãæå®ããªããã¨ãä»®å®ãã¦ããï¼
([1] p.239)
æ¥æ¬èªãããªãåããã¥ããã®ã§ï¼è¦ç´ããã¨ãããããã¸ãã¯ã®ãããªæ°ãããï¼
- SVR4ã§ã¯ï¼å¶å¾¡ç«¯æ«ãå²ãæ¯ããã¦ããªãã»ãã·ã§ã³ãªã¼ãã端æ«ããªã¼ãã³ãããã¨ããã¨ï¼èªåçã«å¶å¾¡ç«¯æ«ãä»ä¸ããã¦ãã¾ã
- ããã¯ããºã¤!
- O_NOCTTYãã©ã°ãæå®ããã°é²ãããã©ï¼å¿ãããããºã¤ãã
- SVR4ã®ç¹æ§ãçºåãããªãããã«ã¯ï¼å«ããã»ã¹ (éã»ãã·ã§ã³ãªã¼ã) ã¤ããã°ããï¼çµï¼
ã§ãï¼ã¾ãï¼ç¾ä»£ã ã£ããSolarisãããªããã°æ°ã«ããªãã¦ããæ°ãããï¼ï¼ï¼ãã¡ããï¼ãã¼ã¿ãã«ãªã³ã¼ããæ¸ãæã«ã¯å¤§åã§ãããã©ï¼
åã®ä¸ã§ã¯ï¼double forkããçç±ã¯ããã§ãã¡ã¤ãã«ã¢ã³ãµã¼ãªã®ã§ï¼éãçãããåç¥ã®æ¹ãããã°æãã¦ãã ããï¼
Reference
- [1] Wã»ãªãã£ã¼ãã»ã¹ãã£ã¼ã´ã³ã¹èï¼å¤§æ¨æ¦é訳ã詳解UNIXããã°ã©ãã³ã°ããã¢ã½ã³ã»ã¨ãã¥ã±ã¼ã·ã§ã³ (2000).
åç2: ã¾ã³ãããã»ã¹çºçãæãããã
Twitter TLä¸ã§å¥ã®åçãçºè¦! (å®ã¯ãã®åçãè¦ã¤ãã¦ï¼ããã¦ã¦ãã£ã¨draftãã¼ã¸ã§ã³ã ã£ãä¸è¨ã®è¨äºãupããã¨ããã¯ã±ã§ã)
double forkã«ãªã£ã¦ããçç±ï¼waitãå¿ããã¨ã¾ã³ãããã»ã¹ãçºçããããããã£ã¨çåã ã£ããã ãã©ç´å¾ããã #tork03
by kuenishi (http://twitter.com/kuenishi/status/9768707555)
親ããã»ã¹ãæ»ã¬ã¨åããã»ã¹ãinitã®é¤åã«ãªããinitã¯waitãã¾ãã£ã¦ãã®ã§ã¾ã³ãããã»ã¹ãååã§ãã¦ããã #tork03
by kuenishi (http://twitter.com/kuenishi/status/9768731754)
ã¨ï¼å¼ç¨ããã¯ããããã©ï¼waitãå¿ããã¨ã¾ã³ãããã»ã¹ãçºçããçç±ãã¾ã ããã£ã¦ããªã(´・Ïï½¥ï½)ï¼ãã¨ã§ãã£ããåå¼·ãããï¼