Search code examples
androidprocesssuthread-priority

How can i avoid android background process starvation?


I'm running a native background process from an android app with Runtime.exec().

It seems like every few seconds the process is put to sleep for like 200 ms.
It looks like the android operating system is just starving that process.

Is there some way I can change the process priority from a background process to some other type of priority?

Assume the application that's running the process can get super user access.

Edit:

The command I'm using to run the process:

String fullCommand = "export LD_LIBRARY_PATH=LD_LIBRARY_PATH:. && ./MyProc";

Runtime.getRuntime().exec(new String[]{"su", "-c ", fullCommand });

Solution

  • If you know the PID of the process, you can change its priority with renice (taken from this answer).

    You can call renice like this:

    renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]