Nodejs Processes

1

I would like to know how to get all processes with nodejs equal to C #

Process[] processlist = Process.GetProcesses();

I would like to do this in NODEJS, to return all the PIDs of the computer, not just the nodejs

    
asked by anonymous 07.08.2016 / 19:34

1 answer

0

Yes, you need to use process = require ('process'); Then

To get the process you need the process ID:

if (process.pid) {
  console.log('Este processo é seu pid' + process.pid);
}

To get the platform:

console.log('Esta plataforma é ' + process.platform);

Update to your requirements. (WINDOWS Test)

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

exec('tasklist', function(err, stdout, stderr) { 
    var lines = stdout.toString().split('\n');
    var results = new Array();
    lines.forEach(function(line) {
        var parts = line.split('=');
        parts.forEach(function(items){
        if(items.toString().indexOf(yourPID) > -1){
        console.log(items.toString().substring(0, items.toString().indexOf(yourPID)));
         }
        }) 
    });
});

In linux it's something like this:

var spawn = require('child_process').spawn,
    cmdd = spawn('your_command'); //something like: 'man ps'

cmdd.stdout.on('data', function (data) {
  console.log('' + data);
});
cmdd.stderr.setEncoding('utf8');
cmdd.stderr.on('data', function (data) {
  if (/^execvp\(\)/.test(data)) {
    console.log('Failed to start child process.');
  }
});

Retired from here!

    
27.01.2018 / 16:34