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);

    }
3
  • Thank you. That helped me. Not sure why I didn't see it during my google search. Commented Jul 3, 2014 at 19:15
  • No worries. I've done it a lot of times too. Commented Jul 3, 2014 at 19:18
  • 1
    Not really a duplicate of that question, as this question is about the PID of a child process rather than the PID of the current process. Commented Jul 3, 2014 at 21:58

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.