简体   繁体   English

如何避免android后台进程饥饿?

[英]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.

相关问题 我如何模仿一个Android进程成为后台进程? - How can I mimic an android process becoming a background process? Android:为什么如果我创建一个位图,该位图将在过程中覆盖前一个,则占用的内存会增加? 我该如何避免呢? - Android: Why if I create a bitmap that will overwrite the previous during a process the occupied ram increases? How can I avoid it? Android中的SlideDrawer总是以透明方式显示,如何设置背景并避免透明 - SlideDrawer in android always apper as transparent , how can i set background and avoid transparent 我如何一次运行到后台进程 - how can I run to background process at once 如何在android上创建在后台进程中设置计时器的程序 - How can create program that set timer in background process on android 如何在Android的后台线程中处理位图? - How do I process a bitmap in a background thread in Android? 如何在Android中检查后台进程 - How to check for background process in android 如何在android中执行后台进程? - How to perform background process in android? 如何在Android中处理SQLite数据集 - How can I process a SQLite dataset in Android 如何在待机状态下运行Android进程? - How can I run Android process in standby?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM