简体   繁体   中英

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

you can kill it using childProcess.kill([signal]) - signal is SIGTERM if not specified

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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