.\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software .\" must display the following acknowledgement: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors .\" may be used to endorse or promote products derived from this software .\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" @(#) fork. 2 8.1 (Berkeley) 6/4/93 .\" %FreeBSD: src/lib/libc/sys/fork. 2, v 1.9. 2.6 2002/07/30 19:04:25 silby Exp % .\" .\" $FreeBSD: doc/ja_JP.eucJP/man/man2/fork. 2, v 1.7 2002/08/11 19:49:11 horikawa Exp $ .Dd June 4, 1993 .Dt FORK 2 .Os .Sh ¸íĪ .Nm fork .Nd »õ·Î¿î ÇÁ·Î¼¼½º¸¦ ÀÛ¼ºÇÑ´Ù .Sh ÇÁ·Î±×·¥ ¶óÀ̺귯¸® .Lb libc .Sh ¼­½Ä .In sys/types.h .In unistd.h .Ft pid_t .Fn fork void .Sh ÇØ¼³ .Fn fork ¿¡ ÀÇÇØ »õ·Î¿î ÇÁ·Î¼¼½ºÀÇ ÀÛ¼ºÀ» ÇÕ´Ï´Ù. »õ·Î¿î ÇÁ·Î¼¼½º (child process)´Â, ÀÌÇÏÀÇ Ç׸ñÀ» Á¦¿ÜÇÑ È£Ãâ ÇÁ·Î¼¼½º (parent process)ÀÇ Á¤È®ÇÑ Ä«ÇÇÀÔ´Ï´Ù. .Bl -bullet -offset indent .It child process´Â µ¶Æ¯ÇÑ ÇÁ·Î¼¼½º ID ¸¦ °¡Áý´Ï´Ù. .It child process´Â ´Ù¸¥ parent process ID ¸¦ °¡Áý´Ï´Ù (Áï, parent processÀÇ ÇÁ·Î¼¼½º ID ÀÔ´Ï´Ù). .It child process´Â, Àü¿ëÀÇ, ºÎ¸ðÀÇ ±â¼úÀÚÀÇ Ä«ÇǸ¦ °¡Áý´Ï´Ù. ±×·¯ÇÑ ±â¼úÀÚ´Â ÇÏÃþÀÇ °°Àº ¿ÀºêÁ§Æ®¸¦ ÂüÁ¶ÇÕ´Ï´Ù. Áï ¾ÆÀÌ¿Í ºÎ¸ðÀÇ »çÀÌ·Î, ¿¹¸¦ µé¾î ÆÄÀÏ ¿ÀºêÁ§Æ®³»ÀÇ ÆÄÀÏ Æ÷ÀÎÅͰ¡ °øÀ¯µË´Ï´Ù. ±× ¶§¹®¿¡ child processÀÇ ±â¼úÀÚ¿¡°Ô·ÎÀÇ .Xr lseek 2 ÇÏÁö¸¸, ±× ÈÄÀÇ ºÎ¸ð¿¡ ÀÇÇÑ´Ù .Xr read 2 ¶Ç´Â .Xr write 2 ¿¡ ¿µÇâÀ» ¹ÌĨ´Ï´Ù. ÀÌ ±â¼úÀÚ Ä«ÇÇ´Â, »õ·Ó°Ô ÀÛ¼ºµÈ ÇÁ·Î¼¼½º¿ëÀÇ Ç¥ÁØ ÀÔÃâ·ÂÀ» È®¸³Çϱâ À§Çؼ­, ¹× ÆÄÀÌÇÁ¸¦ ¼Â¾÷ Çϱâ À§Çؼ­, ½©¿¡ ÀÇÇØµµ »ç¿ëµË´Ï´Ù. .It child processÀÇ ¸®¼Ò½º »ç¿ë »óȲÀº 0 À¸·Î ¼³Á¤µË´Ï´Ù. .Xr setrlimit 2 (À»)¸¦ ÂüÁ¶ÇØ ÁÖ¼¼¿ä. .It ¸ðµç ÀÎÅ͹ú ŸÀ̸Ӱ¡ Ŭ¸®¾î µË´Ï´Ù. .Xr setitimer 2 (À»)¸¦ ÂüÁ¶ÇØ ÁÖ¼¼¿ä. .El .Sh ¹Ýȯ°ª Á¤»óÀûÀ¸·Î ¿Ï·áÇßÀ» °æ¿ì, .Fn fork (Àº)´Â, child process¿¡ °ª 0 À» µ¹·ÁÁÖ¾î, child processÀÇ ÇÁ·Î¼¼½º ID ¸¦ parent process¿¡ µ¹·ÁÁÝ´Ï´Ù. ±×·¸Áö ¾ÊÀº °æ¿ì´Â -1 ÀÌ parent process¿¡ µ¹·ÁÁÖ¾îÁ® child process´Â ÀÛ¼ºµÇÁö ¾Ê°í , ¿¡·¯¸¦ ³ªÅ¸³»±â À§Çؼ­(¶§¹®¿¡) ±Û·Î¹ú º¯¼ö .Va errno ÇÏÁö¸¸ ¼³Á¤µË´Ï´Ù. .Sh ¿¡·¯ ´ÙÀ½ÀÇ °æ¿ì¿¡ .Fn fork (Àº)´Â 󸮿¡ ½ÇÆÐÇØ, child process´Â ÀÛ¼ºµÇÁö ¾Ê½À´Ï´Ù. .Bl -tag -width Er .It Bq Er EAGAIN ½ÇÇàÁßÀÇ ÇÁ·Î¼¼½ºÀÇ ÇÕ°è¼ö°¡ ½Ã½ºÅÛÀÇ ÇѰ踦 ³Ñ½À´Ï´Ù. ÇѰèÄ¡´Â .Xr sysctl 3 ÀÇ MIB º¯¼öÀÇ .Dv KERN_MAXPROC ¿¡ ÀÇÇØ ÁöÁ¤µË´Ï´Ù (½´ÆÛ À¯Àú¸¦ Á¦¿ÜÇØ, ½ÇÁ¦·Î´Â ÇѰè´Â À̰ͺ¸´Ù 10 °³ Àû°Ô µË´Ï´Ù). .It Bq Er EAGAIN À¯Àú°¡ ½´ÆÛ À¯Àú°¡ ¾Æ´Ï°í, 1 ¸íÀÇ À¯Àú¿¡ ÀÇÇØ ½ÇÇàÁßÀÇ ÇÁ·Î¼¼½ºÀÇ ÇÕ°è¼ö¿¡ ½Ã½ºÅÛÀÌ ºÎ°úÇÑ´Ù ÇѰ踦 ³Ñ½À´Ï´Ù. ÇѰè´Â .Xr sysctl 3 ÀÇ MIB º¯¼öÀÇ .Dv KERN_MAXPROCPERUID ¿¡ ÀÇÇØ ÁöÁ¤µË´Ï´Ù. .It Bq Er EAGAIN À¯Àú°¡ ½´ÆÛ À¯Àú°¡ ¾Æ´Ï°í, ¸®¼Ò½º ÆÄ¶ó¹ÌÅÍÀÇ .Dv RLIMIT_NPROC ¿¡ ´ëÀÀÇÏ´Â ¼ÒÇÁÆ® ¸®¼Ò½º ÇѰ踦 ³Ñ½À´Ï´Ù. .Pf ( Xr getrlimit 2 (À»)¸¦ ÂüÁ¶). .It Bq Er ENOMEM »õ·Î¿î ÇÁ·Î¼¼½º¿ëÀÇ ½º¿Ò °ø°£ÀÌ ºÒÃæºÐÇÕ´Ï´Ù. .El .Sh °ü·Ã Ç׸ñ .Xr execve 2 , .Xr rfork 2 , .Xr setitimer 2 , .Xr setrlimit 2 , .Xr vfork 2 , .Xr wait 2 .Sh ¿ª»ç .Fn fork ÇÔ¼ö´Â .At v6 ±×¸®°í µîÀåÇß½À´Ï´Ù.