Fix how processes are killed on Linux

This commit is contained in:
John Luo 2016-02-26 12:41:54 -08:00
parent 06cfdcaf23
commit 8cdc6da20b
1 changed files with 14 additions and 7 deletions

View File

@ -27,7 +27,6 @@ namespace Microsoft.AspNetCore.Server.Testing
private readonly Stopwatch _stopwatch = new Stopwatch(); private readonly Stopwatch _stopwatch = new Stopwatch();
public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger) public ApplicationDeployer(DeploymentParameters deploymentParameters, ILogger logger)
{ {
DeploymentParameters = deploymentParameters; DeploymentParameters = deploymentParameters;
@ -127,26 +126,34 @@ namespace Microsoft.AspNetCore.Server.Testing
private void KillProcess(int processId) private void KillProcess(int processId)
{ {
ProcessStartInfo startInfo;
if (IsWindows) if (IsWindows)
{ {
startInfo = new ProcessStartInfo var startInfo = new ProcessStartInfo
{ {
FileName = "taskkill", FileName = "taskkill",
Arguments = $"/T /F /PID {processId}", Arguments = $"/T /F /PID {processId}",
}; };
var killProcess = Process.Start(startInfo);
killProcess.WaitForExit();
} }
else else
{ {
startInfo = new ProcessStartInfo var killSubProcessStartInfo = new ProcessStartInfo
{ {
FileName = "pkill", FileName = "pkill",
Arguments = $"-TERM -P {processId}", Arguments = $"-TERM -P {processId}",
}; };
var killSubProcess = Process.Start(killSubProcessStartInfo);
killSubProcess.WaitForExit();
var killProcessStartInfo = new ProcessStartInfo
{
FileName = "kill",
Arguments = $"-TERM {processId}",
};
var killProcess = Process.Start(killProcessStartInfo);
killProcess.WaitForExit();
} }
var killProcess = Process.Start(startInfo);
killProcess.WaitForExit();
} }
protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo) protected void AddEnvironmentVariablesToProcess(ProcessStartInfo startInfo)