From 62e947e9fd53020319d367092277969c88f20de1 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 22 Sep 2015 08:53:12 +0200 Subject: [PATCH] [tesh] kill processes in a portable way --- tools/tesh/tesh.pl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tools/tesh/tesh.pl b/tools/tesh/tesh.pl index e83cbc6441..b46be005bf 100755 --- a/tools/tesh/tesh.pl +++ b/tools/tesh/tesh.pl @@ -47,12 +47,14 @@ use Text::ParseWords; use IPC::Open3; use IO::File; -if($^O eq "linux"){ +# Existing OSes: https://metacpan.org/source/SMUELLER/PathTools-3.47/lib/File/Spec.pm +if($^O eq "linux" || $^O eq "MacOS"){ $OS = "UNIX"; -} -else{ +} elsif ($^O eq "MSWin32") { $OS = "WIN"; $ENV{"PRINTF_EXPONENT_DIGITS"} = "2"; +} else { + die "Tesh: Unknown operating system: $^O\n"; } ## @@ -280,9 +282,16 @@ sub exec_cmd { die "fork() failed: $!" unless defined $forked; if ( $forked == 0 ) { # child sleep $time_to_wait; - kill(SIGTERM, $cmd{'pid'}); - sleep 1; - kill(SIGKILL, $cmd{'pid'}); + if ($OS eq "UNIX") { + kill(SIGTERM, $cmd{'pid'}); + sleep 1; + kill(SIGKILL, $cmd{'pid'}); + } elsif ($OS eq "WIN") { + system("TASKKILL /F /T /PID $cmd{'pid'}"); + # /F: Forcefully + # /T: Tree kill + # /PID: poor soul + } exit $time_to_wait; } } -- 2.20.1