#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).
Download Sysinternals Suite from https://technet.microsoft.com/de-de/sysinternals/bb842062.aspx
Make the programs visible by adding the folder (in my case ";d:\scripts\SysintervalsSuite") to the PATH variable in Windows
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
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