How to stop a process started by run.exec() in android
<p>How to stop "ping"? The following code is the way I try, but It fail.</p>

<pre><code>private class pingWifi implements Runnable {
           Process p = null;
    @Override
    public void run() {
        // TODO Auto-generated method stub
        /*
         * WifiInfo info=mWifiManager.getConnectionInfo(); int
         * ip=info.getIpAddress(); String ips=Formatter.formatIpAddress(ip);
         */
        System.out.println("pingWifi runnable");
        String[] shell = new String[] { "/system/bin/sh", "-c", " " };
        Runtime run = Runtime.getRuntime();

        shell[2] = "ping " + ipAddress;
        try {
            p = run.exec(shell);
            if (p.waitFor() != 0) {
                if (p.exitValue() == 1) {
                    byte[] buff = new byte[1024];
                    InputStream is = p.getErrorStream();
                    int c;
                    c = is.read(buff, 0, 1024);
                    System.out.println("ping error: " + new String(buff));
                }
            } else {
                byte[] buff = new byte[1024];
                InputStream is = p.getInputStream();
                int c;
                c = is.read(buff, 0, 1024);
                System.out.println("ping result: " + new String(buff));
                // wait for hardware
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

    }
void stopProcess() {
        if (p != null) {
            p.destroy();
        }else{
            System.out.println("stopProcess: p==null");
        }
    }



    }
private pingWifi mpingWifi = new pingWifi();
    Thread wifiThread = new Thread(mpingWifi);
            wifiThread.start();
</code></pre>

<p>In the onPause I call mpingWifi.stopProcess(),the result is "stopProcess: p==null". And I still can find the ping process in the "ps" list.</p>

<p>I also think to use "pkill ping" command. but "pkill" command is not supported in Android shell.My target is the ping is not "stop" until "home or back" key event happen. Thanks!</p>
