Kill process from node application

烂漫一生 提交于 2019-12-23 04:46:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!