I'm building an Android application that starts a process by calling su and sending it a command, along these lines:
Process su = Runtime.getRuntime().exec( "su" );
DataOutputStream out = new DataOutputStream( su.getOutputStream() );
out.writeChars( "pppd /dev/pts/0" );
out.flush();
When I want to stop the service and kill the pppd process, I'm currently running busybox killall pppd through su like the initial call to pppd. Simply calling su.destroy() fails, even if I use pppd /dev/pts/0 nodetach in the first call, which prevents pppd from forking and creating a background process. killall works, but it could break other applications that rely on pppd.
I'd greatly prefer a scalpel that lets me eliminate the pppd process directly, but short of running ps, searching through the PID's, and calling kill, there doesn't appear to be a decent solution.
Is there a reasonably clean way to kill a process that's been started through su on Android?