Javascript 通过Node.js子进程关闭CS:GO专用服务器

Javascript 通过Node.js子进程关闭CS:GO专用服务器,javascript,node.js,steam,Javascript,Node.js,Steam,我一直试图通过编程控制多个反击:全球攻击专用服务器。一切正常,但我无法完全关闭它。打开服务器时,它会创建两个进程:srcds\u run和srcds\u linux。我很容易做到,它会关闭srcds\u run进程,但是srcds\u linux进程会继续运行,即使服务器关闭。如果我试图杀死所有srcds_linux进程,那么它将杀死所有CSGO服务器,即使我只关闭一个。有没有办法选择相应的srcds\u run和srcds\u linux进程? 这是我目前的代码: 我使用的是Ubuntu服



我一直试图通过编程控制多个反击:全球攻击专用服务器。一切正常,但我无法完全关闭它。打开服务器时,它会创建两个进程:
srcds\u run
srcds\u linux
。我很容易做到,它会关闭
srcds\u run
进程,但是
srcds\u linux
进程会继续运行,即使服务器关闭。如果我试图杀死所有
srcds_linux
进程,那么它将杀死所有CSGO服务器,即使我只关闭一个。有没有办法选择相应的
srcds\u run
srcds\u linux
进程?

这是我目前的代码:

我使用的是Ubuntu服务器,使用的是node.js上的

感谢您的帮助:)

因此,感谢@dvlsg,我正在使用
pgrep
关闭相应的
srcds\u linux
进程。这是我目前掌握的代码

var child_process = require('child_process');
var exec = child_process.exec;

function execute(command, callback){
    exec(command, function(error, stdout, stderr) {
        callback(stdout, error, stderr);
    });
};


// Turns off the server if not already off

Server.prototype.stop = function(callback) {

    if(this.online) {

        // Turn server off

        console.log('Stopping server');

        var processId = this.process.pid;

        execute('pgrep -P ' + processId, function(childId, error, stderror) {
            console.log('Parent ID: ' + processId);
            console.log('Child  ID: ' + childId);

            this.process.on('exit', function(code, signal) {

                console.log('Recieved event exit');
                execute('kill ' + childId);
                this.online = false;
                callback();

            });

            this.process.kill();

        });

    } else {
        this.online = false;
        callback();
    }

}

如果我改进了代码,我会更新它,但这是我目前所拥有的。

没想到会看到CS:GO相关的东西,哈哈,是的。我也许看到了这一点,但是没有多少是
srcds\u运行
spoking
srcds\u linux
?它是否可能是
srcds\u linux
的父进程,您可以通过
pgrep
或类似的方式获取其进程id?您应该能够在节点中获得原始派生进程的进程id,谢谢,dvlsg!这正是我需要的。一旦我启动并运行了,我会在下面发布一个带有工作代码的答案。嘿,这很酷。使用Node js和CSGO还可以做什么?
var child_process = require('child_process');
var exec = child_process.exec;

function execute(command, callback){
    exec(command, function(error, stdout, stderr) {
        callback(stdout, error, stderr);
    });
};


// Turns off the server if not already off

Server.prototype.stop = function(callback) {

    if(this.online) {

        // Turn server off

        console.log('Stopping server');

        var processId = this.process.pid;

        execute('pgrep -P ' + processId, function(childId, error, stderror) {
            console.log('Parent ID: ' + processId);
            console.log('Child  ID: ' + childId);

            this.process.on('exit', function(code, signal) {

                console.log('Recieved event exit');
                execute('kill ' + childId);
                this.online = false;
                callback();

            });

            this.process.kill();

        });

    } else {
        this.online = false;
        callback();
    }

}