os.cpus()
- 返回:对象[]
返回一个包含每个逻辑 CPU 核心信息的对象数组。如果无法获取 CPU 信息,例如 /proc 文件系统不可用,则数组将为空。
【Returns an array of objects containing information about each logical CPU core.
The array will be empty if no CPU information is available, such as if the
/proc file system is unavailable.】
每个对象上包含的属性包括:
【The properties included on each object include:】
[
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 252020,
nice: 0,
sys: 30340,
idle: 1070356870,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 306960,
nice: 0,
sys: 26980,
idle: 1071569080,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 248450,
nice: 0,
sys: 21750,
idle: 1070919370,
irq: 0,
},
},
{
model: 'Intel(R) Core(TM) i7 CPU 860 @ 2.80GHz',
speed: 2926,
times: {
user: 256880,
nice: 0,
sys: 19430,
idle: 1070905480,
irq: 20,
},
},
] nice 值仅适用于 POSIX。在 Windows 上,所有处理器的 nice 值始终为 0。
不应使用 os.cpus().length 来计算应用可用的并行数量。应使用 os.availableParallelism() 来实现此目的。