Replacing KillProcess with taskkill /t which kills entire process tree
This commit is contained in:
parent
19501c03aa
commit
899fe193e7
|
|
@ -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 =
|
||||
|
|
|
|||
Loading…
Reference in New Issue