Skip to main content
PowerShell: moved init of counter out of the loop, last batch line:
Source Link
Kab
  • 165
  • 7

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $$counter = 0;    
Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"    
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1%~dp0\pf1.ps1

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

$counter = 0;    
Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"    
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file %~dp0\pf1.ps1
change in powershell script: from 18200 pages to 1M pages for deletion-limit
Source Link
Kab
  • 165
  • 7

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 18200) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$$i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 18200) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 1000000) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1
added 966 characters in body
Source Link
Kab
  • 165
  • 7

I#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 18200) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1

I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica

#cmd script# I tried Pillsys Method but didn't have any success. So I tried a different route by writing a batch file that will monitor the MathKernels and kills them if they have a page fault of over one million. Credit goes to DavidPostill for pointing me to Sysinternals (see here).

  1. Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx

  2. Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows

  3. Add the folowing script in "d:\scripts\checkmathkernels.bat":

    @echo off
    SETLOCAL ENABLEEXTENSIONS
    setlocal EnableDelayedExpansion
    REM Dieses script soll MathKernels schließen die eine zu hohe (>1M) page fault haben. Es prüft alle 60 Sekunden.
    REM Der folgende Aufruf liest alle MathKernel Prozesse aus. PIDs sind an Stelle 2. (Page)Faults sind an Stelle 7.
    REM pslist -m -nobanner MathKernel | findstr /C:"MathKernel"
    :start
    set "output_cnt=0"
    for /f "tokens=2,7 " %%e in ('pslist -m -nobanner MathKernel ^| findstr /C:"MathKernel"') do (
        set /a output_cnt+=1    
        set "pids[!output_cnt!]=%%e"    
        set "faults[!output_cnt!]=%%f"    
    )
    REM Ausgabe:
    echo PID  faults
    for /L %%n in (1 1 !output_cnt!) DO (
        if !faults[%%n]! GTR 1000000 (
        call taskkill /f /PID !pids[%%n]!
    )
    echo !pids[%%n]! !faults[%%n]!
    )
    timeout /T 60
    goto start
    
  4. Call bat from Mathematica or start it with a doubleclick

##PowerShell If you want to avoid using Sysintervals you could use the following PowerShell Script (tested on Win7 SP1, PowerShell v5):

Do {
$pr = Get-WmiObject -Query "select * from win32_process where name='MathKernel.exe'"
$counter = 0;
foreach ($i in $pr) {
    Write-Output "Process $($i.Handle) has $($i.PageFaults) PageFaults"
    If ($i.PageFaults -ge 18200) {        
        Stop-Process $i.Handle -Force
        $counter++
        Write-Output "Process $($i.Handle) stopped"
    }
}
Write-Output "$($counter) processes stopped so far"
Start-Sleep -Seconds 60
} Until ( $Host.UI.RawUI.KeyAvailable -and ($Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").VirtualKeyCode -eq 27 ) )  

If you save it as "pf1.sh1" you can call it from a bat file in the same directory with

powershell.exe -noprofile -executionpolicy bypass -file .\pf1.ps1
Source Link
Kab
  • 165
  • 7
Loading