简体   繁体   English

从节点应用程序终止进程

[英]Kill process from node application

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) {
....
    });
var child = exec(cmd, function(error, stdout, stderr) { ... });

// When you want to kill it:
child.kill(SIGNAL);

See the documentation . 请参阅文档

exec returns a childProcess object exec返回一个childProcess对象

you can kill it using childProcess.kill([signal]) - signal is SIGTERM if not specified 您可以使用childProcess.kill([signal])杀死它-如果未指定,则信号为SIGTERM

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM