Here you can find the source of findProcessIdWithPS(String command)
public static int findProcessIdWithPS(String command) throws Exception
//package com.java2s; /* See LICENSE for licensing information */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public final static String SHELL_CMD_PS = "ps"; public static int findProcessIdWithPS(String command) throws Exception { int procId = -1; Runtime r = Runtime.getRuntime(); Process procPs = null;//from w w w. j av a 2 s .co m procPs = r.exec(SHELL_CMD_PS); BufferedReader reader = new BufferedReader(new InputStreamReader( procPs.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { if (line.indexOf(' ' + command) != -1) { StringTokenizer st = new StringTokenizer(line, " "); st.nextToken(); // proc owner procId = Integer.parseInt(st.nextToken().trim()); break; } } return procId; } }