是的,内置/核心模块可以
process做到这一点:
所以,只要说
var process =require('process');然后
if (process.pid) { console.log('This process is your pid ' + process.pid);}
获取平台信息:
console.log('This platform is ' + process.platform);
注意: 您只能了解子进程或父进程的PID。
根据您的要求进行了更新。(经过测试
WINDOWS)
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))); } }) });});
在
Linux你可以尝试这样的:
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.'); }});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)