0

I need to know the terminals PID while running a node app (not the APPs PID !!).

If I am right, the parent PID should be what I like to know. But I couldn't find a property holds this. I assume this is due to the reason it isn't implemented in node.js.

That way I need to do this by a child_process like this:

// my function ...
var ppid = null;
var cp = require('child_process');
if(process.platform === 'darwin' || 'freebsd' || 'linux' || 'sunos') {
  cp.exec('ps -o ppid='+process.pid, function(error, stdout) {
    ppid = stdout.split('\n')[1].trim();
    return ppid;
  });
} else if(process.platform === 'win32') {
  // windows cmd pid
  cp.exec('wmic process where (processid='+process.pid+') get parentprocessid', function(error, stdout) {
    ppid = stdout.split('\n')[1].trim();
    return ppid;
  });
}

Is there any better idea ?

Danny
  • 1,078
  • 7
  • 22
  • 1
    I think this is answered [here](http://stackoverflow.com/questions/15471555/nodejs-process-info) – Philip O'Brien Sep 16 '15 at 14:16
  • If you look, I did in fact link to the relevant answer. – Philip O'Brien Sep 17 '15 at 08:58
  • @robocode not as and comment or an answer. It would be enough to do this. Marking as duplicate is such a stupid way - it also looks like others are following (but it simple isn't a duplicate !!!) - Here is something very wrong by system ! – Danny Sep 17 '15 at 09:50
  • @Danny I don't want to get drawn into an argument. I used to get defensive when one of my questions was marked as duplicate, but you know what, it's a good system. I come to SO looking for answers, and the faster I can find them the better. To facilitate that the less duplication clogging up the system the better. If you feel your question isn't a duplicate then it's a fault of how you phrased it, because it reads exactly like a duplicate. – Philip O'Brien Sep 17 '15 at 09:54

0 Answers0