403Webshell
Server IP : 167.235.67.158  /  Your IP : 216.73.216.179
Web Server : Apache
System : Linux ubuntu-8gb-nbg1-1 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64
User : upstairsbar.co.uk ( 982)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/node_modules/pm2/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/node_modules/pm2/lib/TreeKill.js
'use strict';

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

module.exports = function (pid, signal, callback) {
  pid = parseInt(pid, 10);
  if (isNaN(pid)) {
    if (callback) return callback(new Error('pid must be a number'));
    return;
  }

  if (process.platform === 'win32') {
    exec('taskkill /pid ' + pid + ' /T /F', { windowsHide: true }, function (err) {
      if (callback) return callback(err, [pid]);
    });
    return;
  }

  // Unix (Linux, macOS, FreeBSD)
  // 1) Snapshot all processes in one ps call
  // 2) Build the descendant tree in JS
  // 3) Kill bottom-up (deepest children first)
  var ps = spawn('ps', ['-e', '-o', 'pid=,ppid=']);
  var allData = '';

  ps.on('error', function (err) {
    if (callback) return callback(err);
  });

  if (ps.stdout) {
    ps.stdout.on('data', function (data) {
      allData += data.toString('ascii');
    });
  }

  ps.on('close', function (code) {
    if (code !== 0 && allData.length === 0) {
      killPid(pid, signal);
      if (callback) return callback();
      return;
    }

    var childrenMap = {};
    var lines = allData.trim().split('\n');

    lines.forEach(function (line) {
      var parts = line.trim().split(/\s+/);
      if (parts.length < 2) return;
      var cpid = parseInt(parts[0], 10);
      var ppid = parseInt(parts[1], 10);
      if (isNaN(cpid) || isNaN(ppid)) return;
      if (!childrenMap[ppid]) childrenMap[ppid] = [];
      childrenMap[ppid].push(cpid);
    });

    // Collect all descendants depth-first
    var descendants = [];
    function collect(parentPid) {
      var kids = childrenMap[parentPid];
      if (!kids) return;
      kids.forEach(function (kid) {
        collect(kid);
        descendants.push(kid);
      });
    }
    collect(pid);

    // Kill bottom-up: deepest children first, then root
    var allPids = descendants.concat(pid);
    allPids.forEach(function (dpid) {
      killPid(dpid, signal);
    });

    if (callback) return callback(null, allPids);
  });
};

function killPid(pid, signal) {
  try {
    process.kill(parseInt(pid, 10), signal);
  } catch (err) {
    if (err.code !== 'ESRCH')
      console.error(err);
  }
}

Youez - 2016 - github.com/yon3zu
LinuXploit