From c997f3e0090576e55955d401b93d5fac76883a80 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 18 Sep 2024 14:36:36 +0200 Subject: [PATCH] processhelp.pm: improve `taskkill` calls (Windows) - drop `tasklist` call before `taskkill`. `taskkill` offers two ways to kill a `pid`: 1. `-pid ` If `` is missing it returns 128 and outputs: ``` ERROR: The process "" not found. ``` 2. `-fi "PID eq "` If `` is missing, it returns 0 and outputs: ``` INFO: No tasks running with the specified criteria. ``` The curl runner script doesn't check the result of the call and both stdout and stderr are redirected to NUL. Meaning the `tasklist` calls pre-verifying if the PID exists are not necessary and we can drop them to put less strain on the runner environment. - log a `taskkill` call missed earlier. Follow-up to e53523fef07894991c69d907a7c7794c7ada4ff4 #14859 - streamline `taskkill` calls by using the `-pid` option (was `-fi `). - make `taskkill` in `pidterm()` use `-t` to kill the process tree. Ref: #11009 Closes #14959 --- tests/processhelp.pm | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/tests/processhelp.pm b/tests/processhelp.pm index 44c6411cda..0a0ce1939e 100644 --- a/tests/processhelp.pm +++ b/tests/processhelp.pm @@ -167,13 +167,10 @@ sub pidterm { if ($pid > 65536 && os_is_win()) { $pid -= 65536; if($^O ne 'MSWin32') { - my $filter = "PID eq $pid"; - # https://ss64.com/nt/tasklist.html - my $result = `tasklist -fi \"$filter\" 2>nul`; - if(index($result, "$pid") != -1) { - # https://ss64.com/nt/taskkill.html - system("taskkill -fi \"$filter\" >nul 2>&1"); - } + # https://ss64.com/nt/taskkill.html + my $cmd = "taskkill -t -pid $pid >nul 2>&1"; + logmsg "Executing: '$cmd'\n"; + system($cmd); return; } } @@ -195,17 +192,10 @@ sub pidkill { if ($pid > 65536 && os_is_win()) { $pid -= 65536; if($^O ne 'MSWin32') { - my $filter = "PID eq $pid"; - # https://ss64.com/nt/tasklist.html - my $cmd = "tasklist -fi \"$filter\" 2>nul"; + # https://ss64.com/nt/taskkill.html + my $cmd = "taskkill -f -t -pid $pid >nul 2>&1"; logmsg "Executing: '$cmd'\n"; - my $result = `$cmd`; - if(index($result, "$pid") != -1) { - # https://ss64.com/nt/taskkill.html - my $cmd = "taskkill -f -t -fi \"$filter\" >nul 2>&1"; - logmsg "Executing: '$cmd'\n"; - system($cmd); - } + system($cmd); return; } } -- 2.47.3