1

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?

vrbsm
  • 1,188
  • 15
  • 22

2 Answers2

3

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.

Andrei Vinogradov
  • 1,865
  • 15
  • 32
  • 1
    Perhaps `-9` is not necessary. The fact that the parent process is `init` should make no difference, should it? – salezica Jan 25 '17 at 15:19
  • 1
    Yes, I think it should make really no difference. But if author have problems with terminating proc - I thing SIGKILL could help. – Andrei Vinogradov Jan 26 '17 at 21:23
  • What's the difference between **killBackgroundProcess**? – IgorGanapolsky Oct 18 '17 at 20:47
  • 1
    @IgorGanapolsky I've fixed me reply. I've meant killBackgroundProcess**es**. It allows you to kill processes with UID that differs from your application while **killProcess** can terminate only processes with same UID as your app. – Andrei Vinogradov Oct 19 '17 at 21:42
1

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);
Unheilig
  • 16,196
  • 193
  • 68
  • 98
BraveAdmin
  • 685
  • 1
  • 6
  • 15