Replacing KillProcess with taskkill /t which kills entire process tree

This commit is contained in:
moozzyk 2016-02-19 14:35:54 -08:00
parent 19501c03aa
commit 899fe193e7
1 changed files with 28 additions and 2 deletions

View File

@ -22,9 +22,12 @@ namespace Microsoft.AspNetCore.Server.Testing
// This is the argument that separates the dotnet arguments for the args being passed to the
// app being run when running dotnet run
public static readonly string DotnetArgumentSeparator = "--";
private static readonly bool IsWindows =
PlatformServices.Default.Runtime.OperatingSystem.Equals("Windows", StringComparison.OrdinalIgnoreCase);
private readonly Stopwatch _stopwatch = new Stopwatch();
public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger)
{
DeploymentParameters = deploymentParameters;
@ -106,8 +109,7 @@ namespace Microsoft.AspNetCore.Server.Testing
if (hostProcess != null && !hostProcess.HasExited)
{
// Shutdown the host process.
hostProcess.Kill();
hostProcess.WaitForExit(5 * 1000);
KillProcess(hostProcess.Id);
if (!hostProcess.HasExited)
{
Logger.LogWarning("Unable to terminate the host process with process Id '{processId}", hostProcess.Id);
@ -123,6 +125,30 @@ namespace Microsoft.AspNetCore.Server.Testing
}
}
private void KillProcess(int processId)
{
ProcessStartInfo startInfo;
if (IsWindows)
{
startInfo = new ProcessStartInfo
{
FileName = "taskkill",
Arguments = $"/T /F /PID {processId}",
};
}
else
{
startInfo = new ProcessStartInfo
{
FileName = "pkill",
Arguments = $"-TERM -P {processId}",
};
}
var killProcess = Process.Start(startInfo);
killProcess.WaitForExit();
}
protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo)
{
var environment =