node获取系统中占用cpu大的程序
node使用两个模块,可以轻松获取当前进程的占用情况:
1. 模块安装
npm install lodash npm install current-processes
2. 实现代码
var _ = require('../node_modules/lodash'); var ps = require('../node_modules/current-processes'); var os = require('os'); ps.get(function(err, processes) { var sorted = _.sortBy(processes, 'cpu'); var top5 = sorted.reverse().splice(0, 5); console.log(top5); });
@南非波波
github:https://github.com/swht