0
Script:
get-process -name fdm -erroraction silentlycontinue
$fdmcount = (get-process -name fdm -erroraction silentlycontinue).count
if ( $fdmcount -gt 1 ){
do {
$LFDM = (Get-WmiObject -Class Win32_Process -Filter "Name = 'fdm.exe'" | select -last 1)
$LPID = $LFDM.handle
echo "kill $LPID"
stop-process -id $LPID -force
# start-sleep 1
get-process -name fdm -erroraction silentlycontinue
$fdmcount = (get-process -name fdm -erroraction silentlycontinue).count
} while ( $fdmcount -gt 1 )
}
1) I run this script to kill the duplicate process. When I get-process
again after stop-process
, the process ID is still show out on get-process.
Even if I try wait-process -id $LPID
,(stop-process -id $LPID -force).WaitForExit()
, I still get an incorrect count.
2) But when I put a delay on line 10 (start-sleep
), then it shows the correct count.
May I know why?
Is it because of multi-threading?
Here I attach the result also.
first part without start-sleep, second part with start-sleep