地址:https://www.npmjs.com/package/node-process-watcher
仅使用非常小的资源消耗。
const {node_process_watcher} = require("node-process-watcher");
// or import {node_process_watcher} from "node-process-watcher";
node_process_watcher.on("screen1",(list)=>{
// Print the information of all processes on the system every second
// 每秒打印一次系统上所有进程的信息
console.log(list[0]);
// { id: 4, user_name: 'SYSTEM', cpu: 0, mem: 0, name: 'System' }
node_process_watcher.close("screen1"); // 关闭
})
node_process_watcher.on("screen2",(list)=>{
// Filter specific processes
// 过滤特定的进程
node_process_watcher.pids("screen2",[
list[0].id
])
console.log(list[0]);
if (list.length === 1) {
// Stop listening for information only after all the on events are closed
// 所有的on关闭后才会停止监听信息上的信息
node_process_watcher.close("screen2");
}
})