Killing a stalled process and leaving others running using PowerShell

Since I wrote my post “Using Loadrunner / Performance Center to kill a rogue process“, some colleagues have asked if I could kill a stalled process and leave others up and running. After some “Googling”, I have found that this is possible.

I modified some PowerShell scripts that I found online so that they do what we want. If you paste the code below into a PowerShell script called for example “KillStalledProcesses.ps1”, it will scan through all the processes on a machine and “kill” any that are not responding.

I’ve tested it using SysInternals “Process Explorer” which allows you to “suspend” a running process like in the image below. I suspended the “notepad.exe” process and tested the PowerShell code.

The code correctly identified the suspended process and “killed” it.

(When I tested this with two other running “notepad” processes, it left the two other processes running.)

My thoughts are that we could add the PowerShell script into the “Extra Files” portion of a LoadRunner or Performance Center script and call it on error using the system (command); function described in the initial blog post. This would kill for example a rogue Citrix or SAPGUI client and leave others running during a performance test.

 


[CmdletBinding()]     

( [string[]]$ComputerName = $env:ComputerName)           

($Computer in $ComputerName)

if(!(Test-Connection -ComputerName $Computer -Count 1 -quiet))

Write-Host "$Computer : OFFLINE"           

Continue           

try {

$Processes = Get-Process -ComputerName $Computer -EA Stop

$nProcesses = @($Processes | ? { $_.Responding -eq $false })

catch {

Write-Error "Failed to query processes. $_"

if($nProcesses)

foreach($nProcess in $nProcesses)

$nProcess | select Name, id, MainWindowTitle, Responding

Write-host "Attempting to kill stalled process"

if ($nProcess.Id -ne $PID)

Stop-Process $nProcess.Id}

else

Write-host "No non-responding processes found"

Using LoadRunner / Performance Center to kill a rogue process

I recently saw a question in a discussion forum for LoadRunner and after replying with a potential solution for a friend of mine, I thought that I’d share my solution here as well. My friend was testing using a Citrix client and when the script failed, the Citrix client was left running. This meant that subsequent test iterations would all fail as well.

Testers using other thick clients such as SAPGUI, RDP, TruClient (using Firefox or Chrome), QTP or UFT may also face this issue.

One way to resolve the problem of orphaned process such as this would be to use a command line function to kill the offending process when an error is detected. In the example below, the script kills any instance of the “calc.exe” (calculator) process. You should replace “calc.exe” with the name of the executable / rogue process.

 

 

 

 

 

N.B. You need to be extremely careful with this code (for obvious reasons).

“Below Zero” badges

A few years ago, I spotted an image of an old “Below zero” badge on a Fylde Scout Group website. I really fancied getting these badges for our Scout blankets or for use as an “occasional” badge. Unfortunately the badges are no longer made, so I got in touch with a badge manufacturer to see if they could help out. I updated the design and had some made.

I’ve managed to get my local District Commissioner to approve these as “occasional” badges to be worn on uniform for Cubs and Scouts who have camped out on nights when the temperature has fallen “below zero”. Even without uniform approval, they make great badges for camp blankets / scarves.

The badges are 40mm x 50mm and they’ve been selling for £1.50 each on eBay.

When I can avoid eBay and PayPal fees, I can offer them for £1.20 each with postage charged at cost price.

Get in touch if you’re interested in buying these badges and enjoy your Winter scouting 🙂