I need to get the PID of  java.lang.Process to kill it after sometime. how to achieve this in JAVA.
{
  Process p = Runtime.getRuntime().exec("cmd /c start D:\\SBTool\\Test.bat");
}
I want to get the PID of process p. please help
I need to get the PID of  java.lang.Process to kill it after sometime. how to achieve this in JAVA.
{
  Process p = Runtime.getRuntime().exec("cmd /c start D:\\SBTool\\Test.bat");
}
I want to get the PID of process p. please help
 
    
     
    
    If you're using unix you can cast Process to UnixProcess and you will find the pid in that class
But if you're using windows you will need to to use the waitFor method, and then check if the exitCode is 0 if so you will need to read it using the buffer reader here's an example code:
    p.waitFor();
    if (p.exitValue()==0) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        return reader.readLine();
    }
However you don't need to use the pid to kill the process if that's what you're looking, There's a method inside the Process type that kill it for you
