Stdout flush in fork

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

ruby trunk e$B$G$N$O$J$7$G$9$,e(B,

fork e$B$9$k$H$-$Ke(B STDOUTe$B$He(BSTDERRe$B$re(Bflush
e$B$9$k$H$"$j$^$9$,e(B,

rb_fork e$B$r$$F$$k$He(B, flush e$B$7$F$+$ie(B
forke$B$9$k$^$G$N4V$KB>$N%9%l%C%I$,e(B
e$B:FEYe(BSTDOUTe$B$J$I$K=q$-9~$_$r9T$&2DG=@-$,$J$$$G$O$J$$$H;W$&$N$G$9$,$I$&$Je(B
e$B$s$G$7$g$&e(B?

__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30612] stdout flush in fork”
on Sat, 17 Mar 2007 14:08:03 +0900, [email protected] (Keiju
ISHITSUKA) writes:

|fork e$B$9$k$H$-$Ke(B STDOUTe$B$He(BSTDERRe$B$re(Bflush e$B$9$k$H$"$j$^$9$,e(B,
|
|rb_fork e$B$r$$F$$k$He(B, flush e$B$7$F$+$ie(B forke$B$9$k$^$G$N4V$KB>$N%9%l%C%I$,e(B
|e$B:FEYe(BSTDOUTe$B$J$I$K=q$-9~$_$r9T$&2DG=@-$,$J$$$G$O$J$$$H;W$&$N$G$9$,$I$&$Je(B
|e$B$s$G$7$g$&e(B?

e$B$=$N2DG=@-$O$"$k$H;W$$$^$9$,!“LdBj$G$O$J$$$N$G$O!)e(B
e$BLdBj$J$N$O!Ve(Bflushe$B$5$l$J$$$3$H!W$G$”$C$F!Ve(Bflushe$B$,B?$$$3$H!W$Oe(B
e$B$5$[$ILdBj$K$J$i$J$$$h$&$K;W$$$^$9$,!#e(B

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:30614] the message: “[ruby-dev:30614] Re: stdout flush in
fork”, on Mar/17 16:38(JST) Yukihiro M. writes:

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

|rb_fork e$B$r$$F$$k$He(B, flush e$B$7$F$+$ie(B forke$B$9$k$^$G$N4V$KB>$N%9%l%C%I$,e(B
|e$B:FEYe(BSTDOUTe$B$J$I$K=q$-9~$_$r9T$&2DG=@-$,$J$$$G$O$J$$$H;W$&$N$G$9$,$I$&$Je(B
|e$B$s$G$7$g$&e(B?

e$B$=$N2DG=@-$O$"$k$H;W$$$^$9$,!“LdBj$G$O$J$$$N$G$O!)e(B
e$BLdBj$J$N$O!Ve(Bflushe$B$5$l$J$$$3$H!W$G$”$C$F!Ve(Bflushe$B$,B?$$$3$H!W$Oe(B
e$B$5$[$ILdBj$K$J$i$J$$$h$&$K;W$$$^$9$,!#e(B

STDOUTe$B$Ke(Bflushe$B$7$?$"$He(B, forke$B$9$kA0$Ke(B,
e$BB>$N%9%l%C%I$,e(B, STDOUTe$B$K=q$-9~$`$Ce(B
e$B$F$3$H$Oe(B STDOUTe$B$,e(Bflush
e$B$5$l$F$$$J$$$3$H$K$J$k$H$*$b$&$N$G$9$,e(B?

__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:30619] the message: “[ruby-dev:30619] Re: stdout flush in
fork”, on Mar/17 22:52(JST) Yukihiro M. writes:

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

|STDOUTe$B$Ke(Bflushe$B$7$?$"$He(B, forke$B$9$kA0$Ke(B, e$BB>$N%9%l%C%I$,e(B, STDOUTe$B$K=q$-9~$`$Ce(B
|e$B$F$3$H$Oe(B STDOUTe$B$,e(Bflush e$B$5$l$F$$$J$$$3$H$K$J$k$H$*$b$&$N$G$9$,e(B?

e$B$"$l!)e(B e$B$A$g$C$HD4$YD>$7$F$_$^$7$?!#e(B

rb_fork()e$B$,e(Brb_f_fork()e$B$+$i8F$P$l$k>l9g$K$Oe(Brb_thread_atfork()
e$B$N8F$S=P$78e$G$9$+$i!"B>$N%9%l%C%I$OB8:$7$J$$$H$$J$7$F$h$$e(B
e$B$H;W$$$^$9e(B(YARVe$B$G$O%F!<%V%k$+$i:o=|$9$k$@$1$G<B:]$K%9%l%C%Ie(B
e$B$r;$a$k$h$&$K$7$F$J$$$$?$$$@$1$Ie(B)e$B!#$@$+$iLdBj$J$7!#e(B

e$B$se(B?
rb_f_fork e$B$,e(B rb_fork e$B$r8F$S=P$7e(B,
e$B$=$Ne(Bforke$B$7$?B&$Ge(B rb_thread_atforke$B$7$Fe(B
e$B$$$k$h$&$K8+$($^$9$,e(B?

e$B$=$l$Ke(B, flushe$B$9$k$N$O$=$&$$$&LdBj$G$7$?$C$1e(B? e$B$D$^$je(B,
e$B;R%W%m%;%9B&$G%9e(B
e$B%l%C%I$,@8$-$F$$$F$=$l$,0-$5$9$k2DG=@-$,$"$k$+$ie(B?

__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30616] Re: stdout flush in fork”
on Sat, 17 Mar 2007 17:58:58 +0900, [email protected]
(e$B@PDM7=<ye(B) writes:
|
|e$B$1$$$8$e!w$$$7$D$+$G$9e(B.
|
|In [ruby-dev:30614] the message: “[ruby-dev:30614] Re: stdout flush in
|fork”, on Mar/17 16:38(JST) Yukihiro M. writes:
|
|>e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B
|
|>|rb_fork e$B$r$$F$$k$He(B, flush e$B$7$F$+$ie(B forke$B$9$k$^$G$N4V$KB>$N%9%l%C%I$,e(B
|>|e$B:FEYe(BSTDOUTe$B$J$I$K=q$-9~$_$r9T$&2DG=@-$,$J$$$G$O$J$$$H;W$&$N$G$9$,$I$&$Je(B
|>|e$B$s$G$7$g$&e(B?
|>
|>e$B$=$N2DG=@-$O$"$k$H;W$$$^$9$,!“LdBj$G$O$J$$$N$G$O!)e(B
|>e$BLdBj$J$N$O!Ve(Bflushe$B$5$l$J$$$3$H!W$G$”$C$F!Ve(Bflushe$B$,B?$$$3$H!W$Oe(B
|>e$B$5$[$ILdBj$K$J$i$J$$$h$&$K;W$$$^$9$,!#e(B
|
|STDOUTe$B$Ke(Bflushe$B$7$?$"$He(B, forke$B$9$kA0$Ke(B, e$BB>$N%9%l%C%I$,e(B, STDOUTe$B$K=q$-9~$`$Ce(B
|e$B$F$3$H$Oe(B STDOUTe$B$,e(Bflush e$B$5$l$F$$$J$$$3$H$K$J$k$H$*$b$&$N$G$9$,e(B?

e$B$"$l!)e(B e$B$A$g$C$HD4$YD>$7$F$_$^$7$?!#e(B

rb_fork()e$B$,e(Brb_f_fork()e$B$+$i8F$P$l$k>l9g$K$Oe(Brb_thread_atfork()
e$B$N8F$S=P$78e$G$9$+$i!"B>$N%9%l%C%I$OB8:$7$J$$$H$$J$7$F$h$$e(B
e$B$H;W$$$^$9e(B(YARVe$B$G$O%F!<%V%k$+$i:o=|$9$k$@$1$G<B:]$K%9%l%C%Ie(B
e$B$r;$a$k$h$&$K$7$F$J$$$$?$$$@$1$Ie(B)e$B!#$@$+$iLdBj$J$7!#e(B

e$B$=$l0J30$Ge(Brb_fork()e$B$rD>@\8F$s$@>l9g$K$O!“B>$N%9%l%C%I$O$^$@e(B
e$B@8$-$F$$$k$o$1$G$9$+$i!”$=$A$i$G$$$:$le(Bflushe$B$5$l$k$G$7$g$&!#e(B

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:30630] the message: “[ruby-dev:30630] Re: stdout flush in
fork”, on Mar/19 13:28(JST) Yukihiro M. writes:

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

e$B$H$O$$$(!"e(Bflushe$B$;$M$P$J$i$J$$$N$Oe(Bforke$B$r9T$C$?%9%l%C%I$,=PNOe(B
e$B$7$?$b$N$G!"B>$N%9%l%C%I$,=PNO$7$?$b$N$K$D$$$F$OB>$N%9%l%C%Ie(B
e$B$+$i$$$:$le(Bflushe$B$5$l$k$N$O4V0c$$$J$$$h$&$K;W$$$^$9!#e(B

e$BN;2re(B.

e$B$A$g$C$H4*0c$$$,B3$$$F<+?.$J$/$J$C$F$-$?$1$Ie(B

e$B?.$8$^$9e(B(^^;

forke$B$7$?;R%W%m%;%9$H=PNO$,:.$8$C$A$c$C$FFs=E$K=PNO$5$l$A$c$&e(B
e$B$+$i$H$+$@$C$?$h$&$J!#e(B

e$B$G$7$?$h$Me(B.

__
---------------------------------------------------->> e$B@PDMe(B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30628] Re: stdout flush in fork”
on Mon, 19 Mar 2007 13:20:17 +0900, [email protected]
(e$B@PDM7=<ye(B) writes:

|>rb_fork()e$B$,e(Brb_f_fork()e$B$+$i8F$P$l$k>l9g$K$Oe(Brb_thread_atfork()
|>e$B$N8F$S=P$78e$G$9$+$i!"B>$N%9%l%C%I$OB8:$7$J$$$H$$J$7$F$h$$e(B
|>e$B$H;W$$$^$9e(B(YARVe$B$G$O%F!<%V%k$+$i:o=|$9$k$@$1$G<B:]$K%9%l%C%Ie(B
|>e$B$r;$a$k$h$&$K$7$F$J$$$$?$$$@$1$Ie(B)e$B!#$@$+$iLdBj$J$7!#e(B
|
|e$B$se(B?
|rb_f_fork e$B$,e(B rb_fork e$B$r8F$S=P$7e(B, e$B$=$Ne(Bforke$B$7$?B&$Ge(B rb_thread_atforke$B$7$Fe(B
|e$B$$$k$h$&$K8+$($^$9$,e(B?

e$B$(!<$H!"$=$&$G$9$Me(B(e$BCQe(B

e$B$H$O$$$(!"e(Bflushe$B$;$M$P$J$i$J$$$N$Oe(Bforke$B$r9T$C$?%9%l%C%I$,=PNOe(B
e$B$7$?$b$N$G!"B>$N%9%l%C%I$,=PNO$7$?$b$N$K$D$$$F$OB>$N%9%l%C%Ie(B
e$B$+$i$$$:$le(Bflushe$B$5$l$k$N$O4V0c$$$J$$$h$&$K;W$$$^$9!#e(B

e$B$A$g$C$H4*0c$$$,B3$$$F<+?.$J$/$J$C$F$-$?$1$Ie(B

|e$B$=$l$Ke(B, flushe$B$9$k$N$O$=$&$$$&LdBj$G$7$?$C$1e(B? e$B$D$^$je(B, e$B;R%W%m%;%9B&$G%9e(B
|e$B%l%C%I$,@8$-$F$$$F$=$l$,0-$5$9$k2DG=@-$,$"$k$+$ie(B?

forke$B$7$?;R%W%m%;%9$H=PNO$,:.$8$C$A$c$C$FFs=E$K=PNO$5$l$A$c$&e(B
e$B$+$i$H$+$@$C$?$h$&$J!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30636] Re: stdout flush in fork”
on Mon, 19 Mar 2007 15:26:29 +0900, “Nobuyoshi N.”
[email protected] writes:

|> e$B$H$O$$$(!"e(Bflushe$B$;$M$P$J$i$J$$$N$Oe(Bforke$B$r9T$C$?%9%l%C%I$,=PNOe(B
|> e$B$7$?$b$N$G!“B>$N%9%l%C%I$,=PNO$7$?$b$N$K$D$$$F$OB>$N%9%l%C%Ie(B
|> e$B$+$i$$$:$le(Bflushe$B$5$l$k$N$O4V0c$$$J$$$h$&$K;W$$$^$9!#e(B
|
|e$BDL>o$NN.$l$G$O$=$&$G$9$,!“e(Bfork(2)e$B$,e(BEAGAINe$B$G<:GT$7$?$H$-$K$O%j%H%i%$A0$Ke(B
|sleepe$B$7$F$^$9$+$i!”$=$3$GB>$N%9%l%C%I$+$ie(Bforke$BA0$K=PNO$5$l$F$7$^$&2DG=@-e(B
|e$B$O$”$k$+$b$7$l$^$;$s!#e(B
|
|1.8e$B$@$H%j%H%i%$$7$F$$$?$N$Oe(Bsysteme$B$@$1$@$C$?$s$G$9$,!“e(Brubye$B%l%Y%k$GKh2s$=e(B
|e$B$3$^$GLLE]8+$J$$$H$$$1$J$$$H$$$&$N$b%$%d$J$N$Ge(BProcess.forke$B$b$”$o$;$F$7$^e(B
|e$B$$$^$7$?!#8+Mn$H$7$F$^$7$?!#e(B

e$B%3%_%C%H$7$F$/$@$5$$!#e(B

e$B$J$+$@$G$9!#e(B

At Mon, 19 Mar 2007 13:28:46 +0900,
Yukihiro M. wrote in [ruby-dev:30630]:

e$B$H$O$$$(!"e(Bflushe$B$;$M$P$J$i$J$$$N$Oe(Bforke$B$r9T$C$?%9%l%C%I$,=PNOe(B
e$B$7$?$b$N$G!"B>$N%9%l%C%I$,=PNO$7$?$b$N$K$D$$$F$OB>$N%9%l%C%Ie(B
e$B$+$i$$$:$le(Bflushe$B$5$l$k$N$O4V0c$$$J$$$h$&$K;W$$$^$9!#e(B

e$BDL>o$NN.$l$G$O$=$&$G$9$,!“e(Bfork(2)e$B$,e(BEAGAINe$B$G<:GT$7$?$H$-$K$O%j%H%i%$A0$Ke(B
sleepe$B$7$F$^$9$+$i!”$=$3$GB>$N%9%l%C%I$+$ie(Bforke$BA0$K=PNO$5$l$F$7$^$&2DG=@-e(B
e$B$O$"$k$+$b$7$l$^$;$s!#e(B

1.8e$B$@$H%j%H%i%$$7$F$$$?$N$Oe(Bsysteme$B$@$1$@$C$?$s$G$9$,!“e(Brubye$B%l%Y%k$GKh2s$=e(B
e$B$3$^$GLLE]8+$J$$$H$$$1$J$$$H$$$&$N$b%$%d$J$N$Ge(BProcess.forke$B$b$”$o$;$F$7$^e(B
e$B$$$^$7$?!#8+Mn$H$7$F$^$7$?!#e(B

Index: process.c

— process.c (revision 12090)
+++ process.c (working copy)
@@ -1344,8 +1344,14 @@ rb_fork(int *status, int (chfunc)(void

#ifndef __VMS

  • rb_io_flush(rb_stdout);
  • rb_io_flush(rb_stderr);
    +#define prefork() ( \
  • rb_io_flush(rb_stdout), \

  • rb_io_flush(rb_stderr) \

  • )
    +#else
    +#define prefork() ((void)0)
    #endif

  • prefork();

#ifdef FD_CLOEXEC
if (chfunc) {
@@ -1357,5 +1363,5 @@ rb_fork(int *status, int (chfunc)(void
}
#endif

  • while ((pid = fork()) < 0) {
  • for (; (pid = fork()) < 0; prefork()) {
    switch (errno) {
    case EAGAIN: