From: Tanaka Akira Date: 2000-11-26T15:41:14+09:00 Subject: [ruby-list:26176] Re: fork problem? In article <200011252247.HAA09258@sharui.nakada.kanuma.tochigi.jp>, nobu.nakada@nifty.ne.jp writes: > > fork$B$H(Bthread$B$r:.$<$k$N$O$+$J$jLdBj$N85$G$9!#(B > > $B$$$C$=!"(Bfork_and_kill_other_threads$B$r(Bfork$B$NI8=`;EMM$K$7$A$c(B > > $B$$$^$7$g$&$+!#(B > > $B!!$H$$$&$+!"(Bfork $B$9$k0JA0$N(B thread $B$,?7$7$$%W%m%;%96u4V$G$^$GF0(B > $B$$$F$/$l$F4r$7$$>u67$H$$$&$N$,!"$A$g$C$HA[A|$D$+$J$+$C$?$s$G$9(B > $B$,!#(Bfork $B$7$?;~E@$G$=$N(B thread $B$,(B main $B$K$J$C$F$=$l0J30$OB8:_$7(B > $B$J$$!"$H$$$&$N$G$I$&$G$7$g$&$+!#(B $B$=$l$,(B fork_and_kill_other_threads $B$N0U?^$G$9!#(B ($B=q$/$N$rK:$l$F$$$?$N$GDI5-$7$F$*$-$^$9$,!";&$9$N$O;R%W%m%;%9B&$G$NOC(B $B$G!"?F%W%m%;%9B&$G$OEvA3!"F0$$$?$^$^$G$9!#(B) $B$9$3$79M$($?$N$G$9$,!"%W%m%;%930$H$NDL?.$r9T$J$C$F$$$k(B thread $B$,(B fork $B$GJ#@=$5$l$k$HLdBj$K$J$j$,$A$G$"$k!"$H$$$&$N$O3N$+$@$H;W$$$^$9!#(B # $BNc30$b$"$k$h$&$J5$$b$7$^$9$,!#(Baccept $B$7$F$O(B Thread.new $B$9$k$@$1$N(B # loop $B$H$+!#(B $B$G!"5?Ld$J$N$O%W%m%;%930$H$NDL?.$r(B($BD>@\$K$O(B)$B9T$J$o$J$$(B thread $B$K$D$$$F(B $B$G$9!#(Bthread $B%W%m%0%i%_%s%0$OAG?M(B($B$8$D$O:#2s=i$a$F(B thread $B$r;H$C$?(B)$B$J(B $B$N$G$h$/$o$+$i$J$$$N$G$9$,!"$=$&$$$&$b$N$O(B fork $B;~$K$I$N$h$&$J?6Iq$r<((B $B$9$N$,E,@Z$J$3$H$,B?$$$s$G$7$g$&$+(B? $B$=$l$H$b$=$s$J(B thread $B$OIaDL;H$o$l(B $B$J$$(B? $B$A$J$_$K!"(BThe Single UNIX (R) Specification, Version 2 $B$rD4$Y$F$_$k$H!"(B fork(2) $B$O$^$5$K(B fork_and_kill_other_threads $B$N$h$&$JF0:n$r$9$k$h$&$G(B $B$9!#(B A process is created with a single thread. If a multi-threaded process calls fork(), the new process contains a replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal safe operations until such time as one of the exec functions is called. Fork handlers may be established by means of the pthread_atfork() function in order to maintain application invariants across fork() calls. $B$=$7$F!"FCJL$J$3$H$r$7$?$$>l9g$K$O(B pthread_atfork $B$G(B fork $B;~$K