[英]How can i avoid android background process starvation?
I'm running a native background process from an android app with Runtime.exec()
. 我正在使用
Runtime.exec()
从android应用程序运行本机后台进程。
It seems like every few seconds the process is put to sleep for like 200 ms. 似乎每隔几秒钟,该过程就会进入休眠状态约200毫秒。
It looks like the android operating system is just starving that process. 看来android操作系统只是在饿死那个进程。
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 });
If you know the PID of the process, you can change its priority with renice
( taken from this answer ). 如果您知道进程的PID,则可以使用
renice
更改其优先级( 从此答案中获取 )。
You can call renice like this: 您可以这样呼叫renice :
renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]
Trying using the .setPriority() method. 尝试使用.setPriority()方法。
Thread t=new Thread();
t.setPriority(Thread.MAX_PRIORITY);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.