更改android中的进程优先级
如何更改Android中的进程优先级?我在android文档
但我没有发现任何通过某种方法改变进程优先级的信息。
ps:我需要这个来测试应用程序的一些与进程优先级相关的功能,并且它不会在程序中使用。
我看到的唯一方法是尝试通过 重要性 字段更改优先级,但我认为这是一个坏主意。
How to change process priority in Android? I have found process description and description of it's priorities in android docs
process and thread description
but I have found nothing on changing process priority by some method.
ps: I need this to test only some feature of application which is connected with process priority and it won't be used in program.
The only way I see is to try to change the priority via importance field, but it's a bad idea I guess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能,除非在有 root 权限的设备上,而且只是暂时的。进程优先级由操作系统管理。如果您的应用程序位于前台,它将以前台优先级运行。如果您的应用程序不在前台,则它不会以前台优先级运行。
然后使用前台进程与非前台进程进行测试。
改变这个数字不太可能产生效果。
RunningAppProcessInfo
是一个输出结构,而不是更改通过该结构报告的任何内容的方法。You can't, except perhaps on a rooted device, and then only temporarily. Process priority is managed by the OS. If your app is in the foreground, it will run with foreground priority. If your app is not in the foreground, it will not run with foreground priority.
Then test with a process that is in the foreground versus one that is not.
Changing that number is unlikely to have an effect.
RunningAppProcessInfo
is an output structure, not a means by which to change anything reported via that structure.原生代码中存在setpriority()和getPriority(),因此我们可以从原生代码中设置优先级。但是,我不确定它是由操作系统生效还是忽略它。
setpriority() and getPriority() in the native code exists, so may be we can set the priority from the native code. But, I am not sure whether it takes effect by the os or neglects it.
这仅适用于 root 设备:
使用终端,通过输入成为 root,
然后从 top 的输出中选择进程 ID,
在 PID 列中查找,并重新指定您想要的进程(在本例中 PID 1825 为优先级 0)
就这样。
请记住,一段时间后,当操作系统认为有必要给予进程更高的优先级时,此更改将被操作系统覆盖。
This only works with a rooted device:
Use a terminal, become root by inputting
then select the process-id from the output of top
look in the column PID and renice the process (in this example PID 1825 to priority 0) you want to by
That's all.
Keep in mind, that this change will be overwritten by the OperatingSystem, after some time, when OS thinks it was necessary to give the process more priority.