Windows 命令行查看 CPU 与内存使用情况全指南

Windows 命令行查看 CPU 与内存使用情况全指南

Windows 命令行查看 CPU 与内存使用情况全指南

在日常使用 Windows 系统进行开发、测试或运维工作时,我们经常需要快速查看系统资源使用情况,如 CPU 使用率、内存占用等。除了使用任务管理器,你还可以通过命令行方式高效获取这些信息。

本篇文章将介绍几种在 Windows 系统中通过命令行查看 CPU 与内存使用情况 的方法,适用于开发者、系统管理员及自动化脚本开发者。

一、通过 CMD 命令查看内存和 CPU 使用情况

1. 查看当前 CPU 使用率(非实时)

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

wmic cpu get loadpercentage

此命令返回当前 CPU 总使用率的百分比,但不是实时刷新数据,适合用于快速快照。

2. 查看物理内存使用情况

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Value

FreePhysicalMemory:剩余可用内存(单位:KB)

TotalVisibleMemorySize:可用物理内存总量(单位:KB)

要换算成 MB,可以手动除以 1024。

二、使用 PowerShell 获取详细资源信息(推荐)

PowerShell 提供了更灵活的数据获取方式,尤其适合脚本自动化处理。

1. 获取总内存和空闲内存(格式化为 MB)

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

Get-CimInstance Win32_OperatingSystem | ForEach-Object {

"总内存: {0:N2} MB" -f ($_.TotalVisibleMemorySize / 1024)

"空闲内存: {0:N2} MB" -f ($_.FreePhysicalMemory / 1024)

}

2. 实时获取 CPU 使用率

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

Get-Counter '\Processor(_Total)\% Processor Time'

如果想持续查看数据:

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

Get-Counter '\Processor(_Total)\% Processor Time' -Continuous

按 Ctrl+C 退出。

三、使用 typeperf 实时输出 CPU 和内存

CMD 中的 typeperf 命令也能实时监控性能指标:

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

typeperf "\Processor(_Total)\% Processor Time" "\Memory\Available MBytes"

每秒输出一条记录,适合实时观察或者重定向保存到日志文件。

四、使用 tasklist 查看各进程内存占用情况

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

tasklist

结果中会列出每个正在运行的进程,以及它们的内存占用(单位:K)。

五、查看系统信息概览

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"

这个命令可以快速提取出系统内存的总量与可用量(英文系统同样适用)。

总结

目的推荐命令快速看 CPU 使用率wmic cpu get loadpercentage快速看总内存和可用内存wmic OS get FreePhysicalMemory,TotalVisibleMemorySize /Value实时性能监控typeperf 命令或 PowerShell Get-Counter精准格式化显示内存(MB)PowerShell + Get-CimInstance查看进程资源占用tasklist

附:如何进入 PowerShell?

在 CMD 中输入:

Choose here

javascripttypescripthtmlcssshellpythongolangjavacc++c#phprubyswiftkotlinscalarustdartelixirhaskellluaperlrsql

powershell

或者在开始菜单中搜索“PowerShell”并打开。

后记

掌握这些命令可以让你快速定位 Windows 系统中的性能瓶颈问题,也方便用于自动化脚本监控场景。如果你对这些命令的批处理或 PowerShell 脚本打包感兴趣,也欢迎留言交流!

相关推荐

在支付宝买定投基金1年半了,越定投亏越多,怎么办? 在理财上有句经典名言是,不懂不要投。什么都不懂就冲进去,不亏才怪呢。文章大纲如下投资前必须要掌握的基础知识介绍具体的指数...
相机维修/保养
365彩票老版本

相机维修/保养

📅 08-02 👁️ 2989
​【商务口语】如何用英语询问和汇报项目进度?