androidserviceprocesssupppd

Killing Root Processes in Android


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?


Solution

  • It turns out that as I progressed on implementing the ppp connection, I no longer needed to manually kill the pppd process. Simply sending a Terminate-Request tells the pppd process that it can close its connection, and the process shuts down after that.

    Regarding the underlying problem, killing a root process nicely, I wasn't unable to find a decent solution. The most effective option still seems to be running busybox killall pppd or manually searching for the process by using ps and basic Java string manipulation.