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 ?