[infra] Clean up task killing on Windows.

Currently task_kill attempts to kill "No" process when no processes with given name are found. For example https://logs.chromium.org/logs/dart/buildbucket/cr-buildbucket/8725661622744325729/+/u/kill_processes__2_/stdout

Follow-up to 86c3959679

Change-Id: I7e76f2ad6351ede530f4d4b0760e47bfacb1476b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404722
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev
2025-01-15 11:25:59 -08:00
committed by Commit Queue
parent 3394fec2c7
commit eddf8443df
+16 -5
View File
@@ -127,9 +127,20 @@ def GetPidsPosix(process_name):
def GetPidsWindows(process_name):
cmd = 'tasklist /FI "IMAGENAME eq %s" /NH' % process_name
cmd = 'tasklist /fo list /FI "IMAGENAME eq %s"' % process_name
# Sample output:
# dart.exe 4356 Console 1 6,800 K
# Image Name: dart.exe
# PID: 26568
# Session Name: Console
# Session#: 1
# Mem Usage: 130,236 K
#
# Image Name: dart.exe
# PID: 22424
# Session Name: Console
# Session#: 1
# Mem Usage: 280,776 K
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
@@ -140,9 +151,9 @@ def GetPidsWindows(process_name):
lines = output.splitlines()
for line in lines:
split = line.split()
if len(split) > 2:
results.append(split[1])
split = line.split(':')
if (len(split) == 2) and (split[0].strip() == 'PID'):
results.append(split[1].strip())
return results