Search code examples
batch-filememorycommand-prompttasklist

Tasklist total memory of specific proces with subprocesses windows


I'm trying to log the memory usage of browsers for exemple for Chrome / Firefox etc.

For Firefox I can simply use this little command line:

tasklist /fo csv /fi "imagename eq firefox.exe" > DumpResults.csv

And this will nicely result with one proces and its usage. But when applying this train of thoughts to Chrome you'll get around 4 processes even when you did a clean launch of Chrome. Is there any way to sum the results?

Sorry for the stupid question but it's my first attempt to create a bat file.


Solution

  • @echo off
    set sum=0
    for /f "tokens=5 delims=," %%x in ('tasklist /fo csv /nh /fi "imagename eq chrome.exe"') do (
      for /f "tokens=1-4 delims=.K " %%a in (%%x) do set /a sum+=%%a%%b%%c%%d
    )
    echo Sum Chrome = %sum%
    

    Maybe you have to adapt the delimiters to your local settings. Output on my computer is like:

    C:\Users> tasklist /fo csv /nh /fi "imagename eq chrome.exe"
    "chrome.exe","7744","Console","1","86.388 K"
    "chrome.exe","7784","Console","1","1.312 K"
    "chrome.exe","7920","Console","1","50.188 K"
    ...