neekey / ps

A Node.js module for looking up running processes
MIT License
128 stars 41 forks source link

stdout of ChildProcess.exec("ps") is cut short not giving the complete args to process #54

Closed peteroreil closed 7 years ago

peteroreil commented 7 years ago

Found on version 0.1.4 /lib/index.js Line 74

If a process is started with a particularly long argument/ multiple arguments,

e.g.node /really/long/absolute/path/to/my/script/myscriptname.js

The object returned ps.lookup for that process will return a truncated version of the argument passed to the script e.g. /really/long/absolute/pa

` else { ChildProcess.exec('ps ' + args, function (err, stdout, stderr) {

  if (err || stderr) {
    return callback(err || stderr.toString());
  }
  else {
    stdout = stdout.toString();
    callback(null, stdout || false);
  }
});`

Function that is causing the problem is the ChildProcess.exec. Suggested solutions are to change from exec to spawn?

http://www.hacksparrow.com/difference-between-spawn-and-exec-of-node-js-child_process.html

Minor workaround is is to pass an option of{ psargs: " " } to the lookup function to limit the size of stdout returned

neekey commented 7 years ago

@peteroreil this is a known issue for 0.1.4 you can switch to 0.1.5 for the moment, or wait for a few days I will release 0.1.6 soon which fixes a small issue brought in 0.1.5 for kill()