From: Martin Quinson Date: Tue, 22 Sep 2015 06:53:12 +0000 (+0200) Subject: [tesh] kill processes in a portable way X-Git-Tag: v3_12~135 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/62e947e9fd53020319d367092277969c88f20de1 [tesh] kill processes in a portable way --- 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; } }