Java获取processId

package com.travelsky.jcf;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SystemUtils {

	public static void main(String[] args) {
		SystemUtils.getPID();
	}

	private static String getPID() {
		String pid = null;
		String cmd = "tasklist";
		try {
			Runtime runtime = Runtime.getRuntime();
			Process process = runtime.exec(cmd);
			BufferedReader br = new BufferedReader(new InputStreamReader(
					process.getInputStream()));
			String line = null;
			while ((line = br.readLine()) != null) {
				if (line.indexOf("javaw") != -1) {
					System.out.println(line.split(" +")[1]);
					System.out.println(line);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return pid;
	}

}

你可能感兴趣的:(process)