Avinash Kharche
Avinash Kharche

Reputation: 441

Script to end/kill piled up Apps/Background processes in windows taskmanager of a exe

We have a java web application in which we are using a pdfconverter exe. Every 4-5 days, the exe getting piled up in the task manager. Atleast 100+ background process/apps of pdfconverter.exe gets piled up. It stops the web application and pdf converter doesn't work. We have to manually end the process through taskmanager. Can you please help me in letting me know if there's any script or automation can be written which monitors the number of processes and kills all the process once exceeded. I want to know which tool can be used to create the script.

Upvotes: 0

Views: 2596

Answers (1)

Mark Wragg
Mark Wragg

Reputation: 23355

You could write a script in PowerShell to monitor how many processes there are and kill them if there are more than a certain number. E.g:

$PDFProcesses = Get-Process pdfconverter.exe

if ($PDFProcesses.count -gt 10) { 
    Try {
        $PDFProcesses | Stop-Process -ErrorAction Stop
    } Catch {
        Write-Warning "Stopping via PS failed. Trying Taskkill.."
        Taskkill.exe /im pdfconverter.exe /f
    }
}

You could then run this as a scheduled task to monitor for the issue at whatever interval you see fit.

Upvotes: 2

Related Questions