Android - How kill process with ppid = 1

926 Views Asked by At

I'm in an android project that performs communication through a satellite modem.

You need to run the pppd command for the modem to make the connection via android.

I performed this command through a bash.

   process = Runtime.getRuntime().exec(new String[]{"su", "root", "-c", "/data/local/android_connect.sh", "&> /mnt/sdcard/Download/log.txt"});

In some moments the android creates this process with PPID = 1

When this happens I can not kill the process by executing the following command

android.os.Process.killProcess(pidProcess);
        if (process != null)
            process.destroy();

Is it possible to kill a process with PPID = 1 through android?

2

There are 2 best solutions below

4
On BEST ANSWER

It's not a good idea, but you can try to call Runtime.getRuntime().exec("kill -9 " + PID);. Or try to call killBackgroundProcesses instead of killProcess. killProcess does not allow you to kill processes with UID that differs from your app UID, while killBackgroundProcesses can do that for you.

And be sure, that your app have permissions like android.permission.ACCESS_SUPERUSER, android.permission.KILL_BACKGROUND_PROCESSES and android.permission.GET_TASKS.

1
On

The PID=1 is the process manager. It's executed directly after the kernel and if you kill it all the processes will die. It's not recommended to so it, but if you're decided you could try this:

Runtime.getRuntime().exec("kill -9 " + PID);