问题
I've used the following code to run some process which is working OK,my question is if there any option to kill this process on demand (by code)
var exec = require('child_process').exec;
var cmd = 'any command';
exec(cmd, function(error, stdout, stderr) {
....
});
回答1:
var child = exec(cmd, function(error, stdout, stderr) { ... });
// When you want to kill it:
child.kill(SIGNAL);
See the documentation.
回答2:
exec returns a childProcess object
you can kill it using childProcess.kill([signal]) - signal is SIGTERM if not specified
来源:https://stackoverflow.com/questions/31676917/kill-process-from-node-application