[ruby1.9] fork と thread

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

native thread e$B$N4X78$H$O;W$$$^$9$,!$e(B
Ruby 1.9 e$B$Ge(B fork e$B$7$?e(B thread e$B0J30$Ge(B waitpid
e$B$G$-$J$$$N$O!$e(B
e$B;EMM$H$7$FHr$1$h$&$,$J$$$3$H$J$N$G$7$g$&$+!)e(B


$ ruby19 -v
ruby 1.9.0 (2008-05-14 revision 0) [i686-linux]

$ irb19
irb(main):001:0> pid = fork { exec kterm }
=> 31383
irb(main):002:0> Process.waitpid(pid)

kterm e$B$r=*N;e(B

=> 31383
irb(main):003:0> pid = fork { exec kterm }
=> 31395
irb(main):004:0> Thread.new{ Process.waitpid(pid) }.value
Errno::ECHILD: No child processes
from (irb):4:in waitpid' from (irb):4:inblock (4 levels) in irb_binding

kterm e$B$r=*N;e(B

irb(main):005:0> Thread.new{ Process.waitpid(fork{ exec kterm })
}.value

kterm e$B$r=*N;e(B

=> 31409

e$B$b$A$m$se(B Ruby 1.8 e$B$G$OLdBj$J$/e(B waitpid
e$B$GBT$D$3$H$,$G$-$^$9!%e(B

e$B5WJ]$G$9!#e(B

2008/5/14 Hidetoshi NAGAI [email protected]:

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

native thread e$B$N4X78$H$O;W$$$^$9$,!$e(B
Ruby 1.9 e$B$Ge(B fork e$B$7$?e(B thread e$B0J30$Ge(B waitpid e$B$G$-$J$$$N$O!$e(B
e$B;EMM$H$7$FHr$1$h$&$,$J$$$3$H$J$N$G$7$g$&$+!)e(B

Linux 2.4 e$B$Ne(B LinuxThreads [email protected])8B$G$7$g$&!#e(B
e$B;n83$7$F$$$^$;$s$,!"e(BLinux 2.6 e$B$de(B Solaris
e$B$G$O4|BTDL$j$KF0$/$+$H!#e(B
e$B;2>He(B:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/30593
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/30610

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

From: KUBO Takehiro [email protected]
Subject: [ruby-dev:34710] Re: [ruby1.9] fork e$B$He(B thread
Date: Thu, 15 May 2008 13:45:55 +0900
Message-ID: [email protected]

native thread e$B$N4X78$H$O;W$$$^$9$,!$e(B
Ruby 1.9 e$B$Ge(B fork e$B$7$?e(B thread e$B0J30$Ge(B waitpid e$B$G$-$J$$$N$O!$e(B
e$B;EMM$H$7$FHr$1$h$&$,$J$$$3$H$J$N$G$7$g$&$+!)e(B

Linux 2.4 e$B$Ne(B LinuxThreads [email protected])8B$G$7$g$&!#e(B
e$B;n83$7$F$$$^$;$s$,!"e(BLinux 2.6 e$B$de(B Solaris e$B$G$O4|BTDL$j$KF0$/$+$H!#e(B

kernel e$B$Oe(B 2.6.15 e$B$G$9!%8E$9$.$^$9$+!)e(B
e$B$=$l$H$be(B kernel option [email protected]_Dj$,2?$+0-$$$H$+$G$7$g$&$+!%e(B

e$B;2>He(B:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/30593
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-dev/30610

e$B$9$$^$;$s!%8+$F$^$;$s$G$7$?!%e(B(^^;

e$B$$$:$l$K$;$h!$e(Bth = Thread.new{Process.waitpid(fork{})}
e$B$J$I$He(B
e$B$7$F$*$$$Fe(B th.join
e$B$H$$$&$h$&$K$G$b$9$k$7$+$J$5$=$&$G$9$M!%e(B(;_:wink:

e$B5WJ]$G$9!#e(B

2008/5/15 Hidetoshi NAGAI [email protected]:

Linux 2.4 e$B$Ne(B LinuxThreads [email protected])8B$G$7$g$&!#e(B
e$B;n83$7$F$$$^$;$s$,!"e(BLinux 2.6 e$B$de(B Solaris e$B$G$O4|BTDL$j$KF0$/$+$H!#e(B

kernel e$B$Oe(B 2.6.15 e$B$G$9!%8E$9$.$^$9$+!)e(B
e$B$=$l$H$be(B kernel option [email protected]_Dj$,2?$+0-$$$H$+$G$7$g$&$+!%e(B

e$B;d$N4D6-e(B Linux kernel 2.6.22, glibc 2.6.1 e$B$G$Oe(B
pid = fork { exec xterm }
Thread.new{ Process.waitpid(pid) }.value
e$B$,F0$-$^$7$?!#e(B(kterm e$B$OF~$l$F$J$$$N$Ge(B xterm e$B$GBeMQe(B)

glibc e$B$N%P!<%8%g%s$,8E$$$+4D6-JQ?te(B LD_ASSUME_KERNEL e$B$re(B
[email protected]_Dj$7$F$$$k$+$N$I$A$i$+$G$O$J$$$+$H!#e(B

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

From: Nobuyoshi N. [email protected]
Subject: [ruby-dev:34712] Re: [ruby1.9] fork e$B$He(B thread
Date: Thu, 15 May 2008 14:26:23 +0900
Message-ID: [email protected]

1.9e$B$K$Oe(BProcess.detache$B$H$$$&%a%=%C%I$b$"$j$^$9!#$^$?!"e(Bforke$B$N$J$$e(B
e$B4D6-$b9M$($l$P!"e(Bfork+exece$B$h$j$be(BProcess.spawne$B$r;H$&$[$&$,$$$$$H;We(B
e$B$$$^$9!#e(B

th = Process.detach(Process.spawn("", )); th.value

e$B$3$l$bF1$8$h$&$KF0$+$J$$$G$7$g$&$+!#e(B

e$B$*$C$7$c$kDL$je(B spawn e$B$r;H$&$Y$-$G$7$?$,!$$=$l$O$=$l$H$7$F!$e(B
[email protected]$$$?%a!<%k$N$h$&$Ke(B detach e$B$9$k$N$G$OF0$-$^$;$s!%e(B

$ irb19
irb(main):001:0> th = Process.detach(Process.spawn(kterm))
=> #<Thread:0xb7a19944 run>
kterm e$B$OF0$+$7$?$^$^e(B
irb(main):002:0> th
=> #<Thread:0xb7a19944 dead> <== e$B%W%m%;%9$N=*N;$rBT$F$:$K;`K4e(B
irb(main):003:0> th =
Thread.new{Process.waitpid(Process.spawn(kterm))}
=> #<Thread:0xb7a14034 run>
irb(main):004:0> th
=> #<Thread:0xb7a14034 sleep>
irb(main):005:0> th.value <== e$B$3$A$i$Oe(B OK
=> 1092

[email protected]$G$9!#e(B

At Thu, 15 May 2008 14:03:58 +0900,
Hidetoshi NAGAI wrote in [ruby-dev:34711]:

e$B$$$:$l$K$;$h!$e(Bth = Thread.new{Process.waitpid(fork{})} e$B$J$I$He(B
e$B$7$F$*$$$Fe(B th.join e$B$H$$$&$h$&$K$G$b$9$k$7$+$J$5$=$&$G$9$M!%e(B(;_:wink:

1.9e$B$K$Oe(BProcess.detache$B$H$$$&%a%=%C%I$b$"$j$^$9!#$^$?!"e(Bforke$B$N$J$$e(B
e$B4D6-$b9M$($l$P!"e(Bfork+exece$B$h$j$be(BProcess.spawne$B$r;H$&$[$&$,$$$$$H;We(B
e$B$$$^$9!#e(B

th = Process.detach(Process.spawn("", )); th.value

e$B$3$l$bF1$8$h$&$KF0$+$J$$$G$7$g$&$+!#e(B

e$B1J0f!wCNG=!%6e9)Bg$G$9!%e(B

From: KUBO Takehiro [email protected]
Subject: [ruby-dev:34714] Re: [ruby1.9] fork e$B$He(B thread
Date: Thu, 15 May 2008 15:27:19 +0900
Message-ID:
[email protected]

e$B;d$N4D6-e(B Linux kernel 2.6.22, glibc 2.6.1 e$B$G$Oe(B
pid = fork { exec xterm }
Thread.new{ Process.waitpid(pid) }.value
e$B$,F0$-$^$7$?!#e(B(kterm e$B$OF~$l$F$J$$$N$Ge(B xterm e$B$GBeMQe(B)

glibc e$B$N%P!<%8%g%s$,8E$$$+4D6-JQ?te(B LD_ASSUME_KERNEL e$B$re(B
[email protected]_Dj$7$F$$$k$+$N$I$A$i$+$G$O$J$$$+$H!#e(B

glibc e$B$Oe(B 2.3.3 e$B$G$7$?!%e(B
e$B$*[email protected]_Dj$7$F$$$J$$e(B (e$B8+Ev$?$i$J$$e(B)
e$B$N$G!$e(B
e$B$I$&$d$ie(B glibc e$B$,8E$9$.$k$H$$$&$3$H$N$h$&$G$9$M!%e(B

e$B$H$O$$$(!$8=4D6-$OHsBP1~$K$9$k$H$$$&$o$1$K$b$$$+$J$$$7!%!%!%e(B(^^;
e$B$I$&$9$k$+9M$($F$
$^$9!%e(B
e$B$"$j$,$H$&$4$6$$$^$7$?!%e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs