进程知识点:http://blog.csdn.net/fanfan4569/article/details/65937555
参考资料:http://lavasoft.blog.51cto.com/62575/15662/
https://segmentfault.com/a/1190000000372192
进程相关类:Proces,ProcessBuilder,Runtime
实例一:(Runtime)
package Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by donal on 2017/3/25.
*/
public class ListAllProcessTest {
public static void main(String[] args) {
BufferedReader br = null;
Process process = null;
try {
process = Runtime.getRuntime().exec("tasklist");
br = new BufferedReader(new InputStreamReader(process.getInputStream(), "GBK"));
String line = null;
System.out.println("列出所有正在运行的进程信息:");
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if(process!=null){
process.destroy();
}
}
}
}
实例二:(ProcessBuilder)
package Test;
/**
* Created by donal on 2017/3/25.
*/
public class PBTest {
public static void main(String args[]) {
try {
ProcessBuilder proc = new ProcessBuilder("notepad.exe", "testfile");
proc.start();
for (int i = 0 ; i < 10; ++ i)
System.out.println(i);
} catch (Exception e) {
System.out.println("Error executing notepad.");
}
}
}