@@ -15,6 +15,28 @@ var restart = null;
15
15
var psTree = require ( 'pstree.remy' ) ;
16
16
var path = require ( 'path' ) ;
17
17
var signals = require ( './signals' ) ;
18
+ var oldKids ;
19
+
20
+ function waitForOldKids ( callback ) {
21
+ if ( oldKids ) {
22
+ // check if all previous kids have been terminated
23
+ exec ( 'kill -0 ' + oldKids . join ( ' ' ) , ( error ) => {
24
+ const returnCode = error ? error . code : 0 ;
25
+ if ( returnCode < 126 ) { // ignore command not found error
26
+ const stillRunningKids = oldKids . length - returnCode ;
27
+ if ( stillRunningKids > 0 ) {
28
+ utils . log . status ( 'still waiting for ' + stillRunningKids +
29
+ ' child process(es) to finish...' ) ;
30
+ setTimeout ( waitForOldKids . bind ( this , callback ) , 100 ) ;
31
+ return ;
32
+ }
33
+ }
34
+ callback ( ) ;
35
+ } ) ;
36
+ } else {
37
+ callback ( ) ;
38
+ }
39
+ }
18
40
19
41
function run ( options ) {
20
42
var cmd = config . command . raw ;
@@ -25,7 +47,14 @@ function run(options) {
25
47
}
26
48
27
49
/*jshint validthis:true*/
28
- restart = run . bind ( this , options ) ;
50
+ var runbinded = run . bind ( this , options ) ;
51
+
52
+ if ( utils . isWindows ) {
53
+ restart = runbinded ;
54
+ } else {
55
+ restart = waitForOldKids . bind ( this , runbinded ) ;
56
+ }
57
+
29
58
run . restart = restart ;
30
59
31
60
config . lastStarted = Date . now ( ) ;
@@ -80,7 +109,7 @@ function run(options) {
80
109
var inBinPath = false ;
81
110
try {
82
111
inBinPath = statSync ( `${ binPath } /${ executable } ` ) . isFile ( ) ;
83
- } catch ( e ) { }
112
+ } catch ( e ) { }
84
113
85
114
// hasStdio allows us to correctly handle stdin piping
86
115
// see: https://git.io/vNtX3
@@ -342,6 +371,7 @@ function kill(child, signal, callback) {
342
371
// note that psTree also works if `ps` is missing by looking in /proc
343
372
const sig = signal . replace ( 'SIG' , '' ) ;
344
373
psTree ( child . pid , function ( err , kids ) {
374
+ oldKids = kids ;
345
375
if ( psTree . hasPS ) {
346
376
spawn ( 'kill' , [ '-s' , sig , child . pid ] . concat ( kids ) )
347
377
. on ( 'close' , callback ) ;
0 commit comments