0

I am working with an C# console application in which I am creating process and when I killing that process it shows that process got killed but process does not get stopped and also application does not exit.

process.StartInfo.WorkingDirectory = @"C:\Users\rajgau\Documents\logstash-2.1.1\bin";
process.StartInfo.FileName = "cmd.exe";

process.StartInfo.UseShellExecute = false;


process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;

process.Start();

process.StandardInput.WriteLine("logstash -f logstash-filename1.conf");

Thread.Sleep(1000 * 10); // atleast some data get loaded
process.StandardInput.Close();
Console.WriteLine("{0} is active: {1}", process.Id, !process.HasExited);
process.Kill();
Console.WriteLine("{0} is active: {1}", process.Id, !process.HasExited);

Also For exiting the console application I tried Environment.Exit(0) but even it did not help.Kindly suggest some points.

Chris Stillwell
  • 10,266
  • 10
  • 67
  • 77
luckycse
  • 215
  • 1
  • 3
  • 13

1 Answers1

1

You are starting a command shell process (cmd.exe) and then also creating child processes (logstash) that you would also need to kill.

You'll need to kill the process tree such as recommended in the answer here https://stackoverflow.com/a/23845431/87464

Community
  • 1
  • 1
nvuono
  • 3,323
  • 26
  • 27