0

I want to be able to kill a ping started from my java program, but I need to get the pid to do so. I also did some research and I found out that I can use SendSignal.exe to send Ctl+C, but I need the pid of the process that I have just started. Is there a way in Java to get the pid?

    Process p = null;
    InputStream processOutput;
    BufferedReader reader = null;
    String line = " ";

    p = Runtime.getRuntime().exec("cmd /c " + command);
    processOutput = p.getInputStream();
    reader = new BufferedReader(new InputStreamReader(processOutput));
    // Read the input
    while((line = reader.readLine()) != null){
        output += line + "\n";
        System.out.println(line);

    }
Ducksauce88
  • 640
  • 3
  • 12
  • 26

1 Answers1

1

Runtime.exec(...) returns a Process object. Would it help if you called process.destroy()?

Solomon Slow
  • 25,130
  • 5
  • 37
  • 57