@@ -72,6 +72,11 @@ exports.create = function (argv, options) {
7272 */
7373 this . pstatus = { } ;
7474
75+ /**
76+ * @ 正常进程数
77+ */
78+ this . okcount = 0 ;
79+
7580 /**
7681 * @ 即将消亡的进程列表
7782 */
@@ -122,6 +127,8 @@ exports.create = function (argv, options) {
122127 delete workers [ pid ] ;
123128 delete _self . pstatus [ pid ] ;
124129 delete _self . dielist [ pid ] ;
130+
131+ _self . okcount = Math . max ( 0 , _self . okcount - 1 ) ;
125132 _self . emit ( 'exit' , pid , code , signal ) ;
126133
127134 if ( ! _self . running ) {
@@ -163,10 +170,12 @@ exports.create = function (argv, options) {
163170 } catch ( e ) {
164171 }
165172 } ) ;
166- for ( var i in _self . dielist ) {
167- if ( workers [ i ] ) {
168- workers [ i ] . kill ( 'SIGTERM' ) ;
169- break ;
173+ _self . okcount ++ ;
174+ if ( _self . okcount >= _options . children / 2 ) {
175+ for ( var i in _self . dielist ) {
176+ if ( workers [ i ] ) {
177+ workers [ i ] . kill ( 'SIGTERM' ) ;
178+ }
170179 }
171180 }
172181 } else if ( 'function' === ( typeof MessageHandle [ msg . type ] ) ) {
@@ -188,6 +197,7 @@ exports.create = function (argv, options) {
188197 n ++ ;
189198 }
190199 } ) ;
200+ _self . okcount = n ;
191201
192202 while ( n < _options . children ) {
193203 _self . _fork ( ) ;
@@ -200,6 +210,7 @@ exports.create = function (argv, options) {
200210 Child . prototype . stop = function ( signal ) {
201211 var _self = this ;
202212 _self . running = 0 ;
213+ _self . okcount = 0 ;
203214
204215 Object . keys ( handles ) . forEach ( function ( i ) {
205216 handles [ i ] . close ( ) ;
@@ -221,6 +232,7 @@ exports.create = function (argv, options) {
221232 /* {{{ public prototype reload() */
222233 Child . prototype . reload = function ( ) {
223234 var _self = this ;
235+ _self . okcount = 0 ;
224236 Object . keys ( workers ) . forEach ( function ( i ) {
225237 _self . dielist [ i ] = true ;
226238 } ) ;
0 commit comments