是的,内置/核心模块process
可实现以下功能:
那就说var process = require('process');
吧
要获取PID(进程ID):
if (process.pid) {
console.log('This process is your pid ' + process.pid);
}
要获取平台信息:
console.log('This platform is ' + process.platform);
Note:您只能了解子进程或父进程的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
岁时,你可以try 以下方式:
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.');
}
});