Here you can find the source of findProcessIdWithPidOf(String command)
public static int findProcessIdWithPidOf(String command) throws Exception
//package com.java2s; /* See LICENSE for licensing information */ import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; import android.util.Log; public class Main { public final static String SHELL_CMD_PIDOF = "pidof"; public static int findProcessIdWithPidOf(String command) throws Exception { int procId = -1; Runtime r = Runtime.getRuntime(); Process procPs = null;//from w ww . java 2 s. c o m String baseName = new File(command).getName(); // fix contributed my mikos on 2010.12.10 procPs = r.exec(new String[] { SHELL_CMD_PIDOF, baseName }); // procPs = r.exec(SHELL_CMD_PIDOF); BufferedReader reader = new BufferedReader(new InputStreamReader( procPs.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { try { // this line should just be the process id procId = Integer.parseInt(line.trim()); break; } catch (NumberFormatException e) { Log.e("TorServiceUtils", "unable to parse process pid: " + line, e); } } return procId; } }