mirror of https://github.com/lukechilds/node.git
Brandon Beacher
15 years ago
committed by
Ryan Dahl
4 changed files with 81 additions and 36 deletions
@ -1,38 +1,34 @@ |
|||||
node.mixin(require("common.js")); |
node.mixin(require("common.js")); |
||||
|
|
||||
if (process.ARGV[2] === "-child") { |
puts("process.pid: " + process.pid); |
||||
node.stdio.open(); |
|
||||
var handler = new node.SignalHandler(node.SIGUSR1); |
|
||||
handler.addListener("signal", function() { |
|
||||
node.stdio.write("handled SIGUSR1"); |
|
||||
setTimeout(function () { |
|
||||
// Allow some time for the write to go through the pipez
|
|
||||
process.exit(0); |
|
||||
}, 50); |
|
||||
}); |
|
||||
debug("CHILD!!!"); |
|
||||
|
|
||||
} else { |
var first = 0, |
||||
|
second = 0; |
||||
|
|
||||
var child = node.createChildProcess(ARGV[0], ['--', ARGV[1], '-child']); |
process.addListener('SIGUSR1', function () { |
||||
|
puts("Interrupted by SIGUSR1"); |
||||
|
first += 1; |
||||
|
}); |
||||
|
|
||||
var output = ""; |
process.addListener('SIGUSR1', function () { |
||||
|
second += 1; |
||||
|
setTimeout(function () { |
||||
|
puts("End."); |
||||
|
process.exit(0); |
||||
|
}, 5); |
||||
|
}); |
||||
|
|
||||
child.addListener('output', function (chunk) { |
i = 0; |
||||
puts("Child (stdout) said: " + JSON.stringify(chunk)); |
setInterval(function () { |
||||
if (chunk) { output += chunk }; |
puts("running process..." + ++i); |
||||
}); |
|
||||
|
|
||||
child.addListener('error', function (chunk) { |
if (i == 5) { |
||||
if (/CHILD!!!/.exec(chunk)) { |
node.kill(process.pid, node.SIGUSR1); |
||||
puts("Sending SIGUSR1 to " + child.pid); |
|
||||
child.kill(node.SIGUSR1) |
|
||||
} |
} |
||||
puts("Child (stderr) said: " + JSON.stringify(chunk)); |
}, 1); |
||||
}); |
|
||||
|
|
||||
process.addListener("exit", function () { |
|
||||
assertEquals("handled SIGUSR1", output); |
|
||||
}); |
|
||||
|
|
||||
} |
process.addListener("exit", function () { |
||||
|
assertEquals(1, first); |
||||
|
assertEquals(1, second); |
||||
|
}); |
||||
|
Loading…
Reference in new issue