Windows平台使用WMIC及批处理记录程序使用内存的情况
程序员文章站
2022-05-12 17:54:52
...
因在Windows平台上需要测试某程序对系统资源--内存的占用情况,经过研究,已可实现,批处理脚本内容如下:
setlocal enabledelayedexpansion
@echo off
set var=0
echo Input the PID
set /p id=PID is:
echo %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% > %id%.txt
:p
for /f "skip=1 tokens=2 delims==" %%a in ('wmic process where "processid='%id%'" get workingsetsize /value') do (
@echo %%a
set /a var=%%a/1024)
@echo %var% K
@echo %var% >> %id%.txt
ping -n 3 127.0.0.1>nul
echo %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% >> %id%.txt
goto p