:new_pgroup and :pgroup option for spawn

process.c $B$G5$$,$D$$$?$N$G$9$,!"(Bspawn $B$K(B Windows $BMQ$N(B
:new_pgroup $B$H$$$&%*%W%7%g%s$,(B
$BA}$($F$$$k$h$&$G$9!#(B

$BD4$Y$F$_$k$H(B [ruby-core:43245] [ruby-trunk - Bug #6131]
$B$,$-$C$+$1$N$h$&$G$9!#(B

$B%I%-%e%a%s%H$K$O0J2<$N$h$&$K@bL@$5$l$F$$$^$9!#(B

  •  create new process group: Windows only
    
  •    :new_pgroup => true  : the new process is the root process
    

of a new process group

  •    :new_pgroup => false : don't create a new process group 
    

(default)

$B$3$l$C$F!"(BUnix $BMQ$N(B :pgroup
$B%*%W%7%g%s$H;w$?F0:n$J$N$G$7$g$&$+(B?

  •  process group:
    
  •    :pgroup => true or 0 : make a new process group
    
  •    :pgroup => pgid      : join to specified process group
    
  •    :pgroup => nil       : don't change the process group 
    

(default)

$B@bL@$rFI$`8B$j!"(B($B$b$7(B Windows $B$N(B process group $B$N35G0$,(B
Unix $B$HF1$8$h$&$J$b$N$J$i(B)
default $B$NF0:n$H(B true $B$NF0:n$O6&DL$N$h$&$K;W$($^$9!#(B

[ruby-core:43245] [ruby-trunk - Bug #6131]
$B$N%9%l%C%I$rFI$s$G$_$?$N$G$9$,!"(B
:pgroup $B$H$N4X78$K$D$$$F$N5DO@$O$J$+$C$?$h$&$K;W$$$^$9!#(B

$B$b$7!"(BUnix $B$H(B Windows $B$G6&DL$K;H$($kF0:n$,$"$k$J$i!"(B
$B6&DL$N%*%W%7%g%s$G;X<($G$-$k$HJXMx$J$N$G$O$J$$$+$H;W$$$^$9!#(B

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45794] :new_pgroup and :pgroup option for spawn.”
on Jun.23,2012 21:56:20, [email protected] wrote:

  •    :new_pgroup => false : don't create a new process group (default)
    

$B$3$l$C$F!"(BUnix $BMQ$N(B :pgroup $B%*%W%7%g%s$H;w$?F0:n$J$N$G$7$g$&$+(B?

Unix$B$N(Bprocess group$B$r$h$/CN$i$J$$$N$GEz$($K$/$$$G$9$M!#(B
$BBg;(GD$K8@$C$F%7%0%J%k$NFO$/HO0O$r$^$H$a$?$b$N$G$“$k!”$H$$$&(B
$BM}2r$,@5$7$$$J$i!“(BWindows$B$N$=$l$O$=$N%5%V%;%C%H$G$”$k$HM}2r$7(B
$B$F:9$7;Y$($J$$$h$&$J5$$,$7$^$9!#(B

  •  process group:
    
  •    :pgroup => true or 0 : make a new process group
    
  •    :pgroup => pgid      : join to specified process group
    
  •    :pgroup => nil       : don't change the process group (default)
    

$B@bL@$rFI$`8B$j!"(B($B$b$7(B Windows $B$N(B process group $B$N35G0$,(B Unix
$B$HF1$8$h$&$J$b$N$J$i(B)
default $B$NF0:n$H(B true $B$NF0:n$O6&DL$N$h$&$K;W$($^$9!#(B

$B$=$&$G$9$M!#(B
($B$J$*(B:pgroup =>
pgid$B$O(Bsetpgid$B$KAjEv$9$k5!G=$,$J$$$N$G$G$-$^$;(B
$B$s(B)

$B$b$7!“(BUnix $B$H(B Windows $B$G6&DL$K;H$($kF0:n$,$”$k$J$i!"(B
$B6&DL$N%*%W%7%g%s$G;X<($G$-$k$HJXMx$J$N$G$O$J$$$+$H;W$$$^$9!#(B

$BF10U$7$^$9!#(B

$B$=$l$G$O!#(B

2012$BG/(B6$B7n(B25$BF|(B 11:27 U.Nakamura [email protected]:

Unix$B$N(Bprocess group$B$r$h$/CN$i$J$$$N$GEz$($K$/$$$G$9$M!#(B
$BBg;(GD$K8@$C$F%7%0%J%k$NFO$/HO0O$r$^$H$a$?$b$N$G$“$k!”$H$$$&(B
$BM}2r$,@5$7$$$J$i!“(BWindows$B$N$=$l$O$=$N%5%V%;%C%H$G$”$k$HM}2r$7(B
$B$F:9$7;Y$($J$$$h$&$J5$$,$7$^$9!#(B

Unix $B$G$b(B process group
$B$O%7%0%J%k$r$=$N%0%k!<%W$KAw$k$3$H$K;H$($k$N$G!“(B
$B6&DL$G$”$k$3$H$,4|BT$G$-$^$9$M!#(B

process group $B$N$R$H$D$NMQK!$H$7$F!“(B
$B30It%W%m%;%9$r5/F0$9$k%7%'%k%9%/%j%W%H$r(B kill $B$9$k$K$O!”(B
Unix $B$G$O!"0J2<$N$h$&$K(B :pgroup $B%*%W%7%g%s$r;H$($^$9!#(B

pid = spawn(“sleep 34; sleep 23”, :pgroup=>true)
sleep 1
Process.kill(:INT, -pid)

:pgroup $B%*%W%7%g%s(B ($B$H(B Process.kill $B$GIi$N(B pid
$B$r;XDj$9$k$3$H$K$h$C$F!“(B
$B%7%0%J%k$rAw$kBP>]$,C10l%W%m%;%9$G$O$J$/%W%m%;%9%0%k!<%W$G$”$k$3$H$r;XDj$9$k$3$H(B)
$B$K$h$C$F!“(B
sh $B$@$1$G$J$/!”(Bsh $B$,5/F0$7$?(B sleep $B$b(B kill $B$G$-$^$9!#(B

Windows $B$G$b!"F1MM$JMQES$K;H$($k$s$G$7$g$&$+(B?
$B$?$H$($P!"8=>u!"0J2<$OF0$/$s$G$7$g$&$+!#(B

pid = spawn(“sleep 34; sleep 23”, :new_pgroup=>true)
sleep 1
Process.kill(:INT, -pid)

2012$BG/(B6$B7n(B25$BF|(B 11:52 U.Nakamura [email protected]:

pid = spawn(“sleep 34; sleep 23”, :new_pgroup=>true)
sleep 1
Process.kill(:INT, -pid)

$B4|BT$5$l$kF0:n$r$4@bL@$/$@$5$$!#(B

sleep
$B$OC1$J$kNc$G!“JL%W%m%;%9$r5/F0$9$k$3$H$K$J$k30It%3%^%s%I$G$”$l$P(B
$B$J$s$G$b$+$^$$$^$;$s!#(B

spawn $B$,5/F0$9$k%7%‘%k(B (Unix $B$G$O(B /bin/sh $B$G$9$,!“(BWindows
$B$G$O0c$&$+$b$7$l$^$;$s(B) $B$N%W%m%;%9$H!”(B
$B%7%’%k$,5/F0$7$?%W%m%;%9$NN>J}$r%7%0%J%k$G;_$a$k$H$$$&$N$,0U?^$7$?F0:n$G$9!#(B

$B$H$$$&$N$O$H$b$+$/!“(B
(1) sleep$B$C$F%3%^%s%I$O$J$$$G$9!#(B
(2) kill$B$O(Bwin32/win32.c$B$K$”$j$^$9!#KAF,$GIi$N(Bpid$B$O(BEINVAL$B$K(B
$B$7$F$*$j$^$9!#(B
$B$N$G!"$3$NNc$G$O(Bspawn$B$b(BProcess.kill$B$bF0$-$^$;$s!#(B

$B$J$k$[$I!#$=$&$9$k$H!"%W%m%;%9%0%k!<%W$K%7%0%J%k$rAw$C$F;_$a$k$K$O(B
$B$I$&$9$k$N$G$7$g$&$+(B?

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45803] Re: :new_pgroup and :pgroup option for
spawn.”
on Jun.25,2012 11:57:59, [email protected] wrote:

$B$J$k$[$I!#$=$&$9$k$H!"%W%m%;%9%0%k!<%W$K%7%0%J%k$rAw$C$F;_$a$k$K$O(B
$B$I$&$9$k$N$G$7$g$&$+(B?

$B%3%s%=!<%k$G(BCtrl+Break$B$G$9$+$M!#(B

$B$=$l$G$O!#(B

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45801] Re: :new_pgroup and :pgroup option for
spawn.”
on Jun.25,2012 11:46:20, [email protected] wrote:

Windows $B$G$b!"F1MM$JMQES$K;H$($k$s$G$7$g$&$+(B?
$B$?$H$($P!"8=>u!"0J2<$OF0$/$s$G$7$g$&$+!#(B

pid = spawn(“sleep 34; sleep 23”, :new_pgroup=>true)
sleep 1
Process.kill(:INT, -pid)

$B4|BT$5$l$kF0:n$r$4@bL@$/$@$5$$!#(B

$B$H$$$&$N$O$H$b$+$/!“(B
(1) sleep$B$C$F%3%^%s%I$O$J$$$G$9!#(B
(2)
kill$B$O(Bwin32/win32.c$B$K$”$j$^$9!#KAF,$GIi$N(Bpid$B$O(BEINVAL$B$K(B
$B$7$F$*$j$^$9!#(B
$B$N$G!"$3$NNc$G$O(Bspawn$B$b(BProcess.kill$B$bF0$-$^$;$s!#(B

$B$=$l$G$O!#(B

2012$BG/(B6$B7n(B25$BF|(B 12:13 U.Nakamura [email protected]:

$B$J$k$[$I!#$=$&$9$k$H!"%W%m%;%9%0%k!<%W$K%7%0%J%k$rAw$C$F;_$a$k$K$O(B
$B$I$&$9$k$N$G$7$g$&$+(B?

$B%3%s%=!<%k$G(BCtrl+Break$B$G$9$+$M!#(B

$B%W%m%0%i%`$+$i9T$&$3$H$O$G$-$J$$!"$H$$$&$3$H$G$7$g$&$+(B?

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45805] Re: :new_pgroup and :pgroup option for
spawn.”
on Jun.25,2012 13:04:32, [email protected] wrote:

$B$J$k$[$I!#$=$&$9$k$H!"%W%m%;%9%0%k!<%W$K%7%0%J%k$rAw$C$F;_$a$k$K$O(B
$B$I$&$9$k$N$G$7$g$&$+(B?

$B%3%s%=!<%k$G(BCtrl+Break$B$G$9$+$M!#(B

$B%W%m%0%i%`$+$i9T$&$3$H$O$G$-$J$$!"$H$$$&$3$H$G$7$g$&$+(B?

GenerateConsoleCtrlEvent$B$G$G$-$k$h$&$J5$$O$7$^$9$,(B($B$H$$$&$+(B
Ruby$B$G$b$d$C$F$k$s$G$9$,(B)$B!"$=$NA0$N(Bspawn$B$NJ}$,Fq$7$/$F$h$/$o(B
$B$+$i$s$+$C$?$j$7$^$9(B :frowning:

$B$=$l$G$O!#(B

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45807] Re: :new_pgroup and :pgroup option for
spawn.”
on Jun.25,2012 13:14:13, [email protected] wrote:

GenerateConsoleCtrlEvent$B$G$G$-$k$h$&$J5$$O$7$^$9$,(B($B$H$$$&$+(B
Ruby$B$G$b$d$C$F$k$s$G$9$,(B)$B!"$=$NA0$N(Bspawn$B$NJ}$,Fq$7$/$F$h$/$o(B
$B$+$i$s$+$C$?$j$7$^$9(B :frowning:

$B!V$=$NA0$N(Bspawn$B!W$H$$$&$N$,;X$7$F$$$k$b$N$,$o$+$i$J$+$C$?$s$G$9$,!"(B
$B;d$N=q$$$?(B
pid = spawn(“sleep 34; sleep 23”, :new_pgroup=>true)
$B$H$$$&ItJ,$G$9$+(B?

$B$(!<$H!“(Bakr$B$5$s$N%3!<%I$N0UL#$,$o$+$i$J$$!”$H$+$8$c$J$/$F!“(B
Windows$B$G!“E,@Z$K%7%'%k$r7PM3$5$;$F!”$=$N>e$G!”%7%‘%k$H%7%’%k(B
$B$+$i5/F0$5$l$?%W%m%;%9$rF10l$N%W%m%;%9%0%k!<%W$K3d$jEv$F$?>u(B
$BBV$r:n$j>e$2$kE,@Z$JJ}K!$,$h$/$o$+$i$J$$!"$N$G$9!#(B

$B$=$l$G$O!#(B

2012$BG/(B6$B7n(B25$BF|(B 13:25 U.Nakamura [email protected]:

$B$(!<$H!“(Bakr$B$5$s$N%3!<%I$N0UL#$,$o$+$i$J$$!”$H$+$8$c$J$/$F!“(B
Windows$B$G!“E,@Z$K%7%'%k$r7PM3$5$;$F!”$=$N>e$G!”%7%‘%k$H%7%’%k(B
$B$+$i5/F0$5$l$?%W%m%;%9$rF10l$N%W%m%;%9%0%k!<%W$K3d$jEv$F$?>u(B
$BBV$r:n$j>e$2$kE,@Z$JJ}K!$,$h$/$o$+$i$J$$!"$N$G$9!#(B

$B$U$`!#:#$N$H$3$m(B :pgroup $B$H(B :new_pgroup
$B$r%^!<%8$7$F$b$&$l$7$/$O$J$$46$8$+$J$!!#(B

$B$“!”!V%3%s%=!<%k$G(BCtrl+Break$B!W$G%W%m%;%9%0%k!<%W=*N;$H$$$&E@$G$9$,!"(B
$B=*N;$9$k$N$O$I$N%W%m%;%9%0%k!<%W$G$7$g$&(B?

Unix $B$G$O!“C<Kv$K(B foreground process group
$B$H$7$F@_Dj$5$l$?%W%m%;%9%0%k!<%W$J$N$G!”(B
$B0J2<$N$h$&$K!"(B:pgroup => true
$B$H$7$F5/F0$7$?%3%^%s%I$O$`$7$m%-!<%!<%I$+$i$N(B
^C ($B$G@8@.$5$l$?(B SIGINT $B%7%0%J%k(B) $B$G$O=*N;$7$J$/$J$j$^$9!#(B

% ruby -e ‘pid = spawn(“sleep 100”, :pgroup => true); sleep’
^C-e:1:in sleep': Interrupt from -e:1:in

zsh: interrupt ruby -e ‘pid = spawn(“sleep 100”, :pgroup => true);
sleep’
% ps auxww|grep sleep
akr 5464 0.0 0.0 5136 580 pts/7 S 14:24 0:00 sleep
100
akr 5467 0.0 0.0 7392 876 pts/7 S+ 14:24 0:00 grep
sleep
%

2012$BG/(B6$B7n(B25$BF|(B 13:10 U.Nakamura [email protected]:

$B%W%m%0%i%`$+$i9T$&$3$H$O$G$-$J$$!"$H$$$&$3$H$G$7$g$&$+(B?

GenerateConsoleCtrlEvent$B$G$G$-$k$h$&$J5$$O$7$^$9$,(B($B$H$$$&$+(B
Ruby$B$G$b$d$C$F$k$s$G$9$,(B)$B!"$=$NA0$N(Bspawn$B$NJ}$,Fq$7$/$F$h$/$o(B
$B$+$i$s$+$C$?$j$7$^$9(B :frowning:

$B!V$=$NA0$N(Bspawn$B!W$H$$$&$N$,;X$7$F$$$k$b$N$,$o$+$i$J$+$C$?$s$G$9$,!"(B
$B;d$N=q$$$?(B
pid = spawn(“sleep 34; sleep 23”, :new_pgroup=>true)
$B$H$$$&ItJ,$G$9$+(B?

$B$@$H$7$?$i$I$3$,$o$+$i$J$+$C$?$N$G$7$g$&(B?

$B$3$s$K$A$O!"$J$+$`$i(B($B$&(B)$B$G$9!#(B

In message “[ruby-dev:45809] Re: :new_pgroup and :pgroup option for
spawn.”
on Jun.25,2012 14:27:27, [email protected] wrote:

$B$U$`!#:#$N$H$3$m(B :pgroup $B$H(B :new_pgroup
$B$r%^!<%8$7$F$b$&$l$7$/$O$J$$46$8$+$J$!!#(B

Unix$B$HF1$85sF0$K$J$k$O$:!“$H;W$C$F;XDj$5$l$F$b!”$“$s$^$j9,J!(B
$B$K$O$J$i$J$5$=$&$@$J$”!"$H$O;W$$$^$9!#(B

$B$“!”!V%3%s%=!<%k$G(BCtrl+Break$B!W$G%W%m%;%9%0%k!<%W=*N;$H$$$&E@$G$9$,!"(B
$B=*N;$9$k$N$O$I$N%W%m%;%9%0%k!<%W$G$7$g$&(B?

Unix $B$G$O!“C<Kv$K(B foreground process group
$B$H$7$F@_Dj$5$l$?%W%m%;%9%0%k!<%W$J$N$G!”(B
$B0J2<$N$h$&$K!"(B:pgroup => true
$B$H$7$F5/F0$7$?%3%^%s%I$O$`$7$m%-!<%!<%I$+$i$N(B
^C ($B$G@8@.$5$l$?(B SIGINT $B%7%0%J%k(B) $B$G$O=*N;$7$J$/$J$j$^$9!#(B

$B$3$NJU$OF1$8$G$9!#(B…$BF1$8$O$:$G$9!#(B
$B!V%3%s%=!<%k$G(BCtrl+Break$B!W$O2?$i$+$N%W%m%;%9%0%k!<%W$K%7%0%J(B
$B%k$rAw$C$F;_$a$kJ}K!$N0lNc$N$D$b$j$@$C$?$N$G!#(B

$B$=$l$G$O!#(B