• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help how to limit the CPU usage of an installed app.

A

Android Question

Guest
Device: galaxy s7 edge (no root)
Apps: GNURoot – Debian (fake root) , Termux (terminal emulator)


I am trying to run some cpu intensive linux software on my phone.
I use the app “GNURoot – Debian” to get a linux terminal. Then I install and run my software.

For a few minutes everything works as expected, but the software soon begins to use up to 300% cpu and the phone will freeze and require reboot.

On my desktops I just use the command “cpulimit -P java -l 20” and this prevents the programs from crashing the desktop.

On the GNURoot - Debian Terminal the command
cpulimit -P java -l 20” will return “Proccess ID xxx detected” but the cpu usage is not actually limited. proccess cpu usage will still shoot up to 300% and crash the phone.

“nice” or “renice” also seem to have no effect.

I have tried to use the “Termux” terminal emulator to use the “cpulimit” command on the entire “GNURoot” app, but it returns “operation not permitted.

I am no linux guru and I am guessing the problem might be that the phone is not rooted, but in my case rooting the devices is not an option.


Can anyone please recommend how I can limit the cpu usage for this app or proccess? I’ve been stuck on this for over a week and am getting nowhere with the little time I have.

Thanks for reading. Your help would be much appreciated.
 
Yeah, I'm not even sure if you could do this if you were rooted, so the fact that you can't change the priority or impact how much CPU resources are consumed when not rooted it not surprising to me...
Thank you "scary alien" I just tried to use "Kill -SIGSTOP ......" and it returned "operation not permitted". so I'm guessing you are right and cpulimit will not work (at least on a non rooted device)

Any other possible approaches on how to prevent the java program from crashing the android system? something like a sandbox environment maybe?
 
Hmm, not sure, @raydroid13...are you seeing an actual crash (i.e., is a stack trace available)?

Other thoughts--in no particular order to possibly assist with debugging:

- watch the Android system logcat while your java program is running:

- from a separate, Android terminal/shell session (Terminal Emulator for Android) or an adb shell from your PC:

adb logcat
- or -​
logcat (from the shell)

Redirect that output to a file for later review, of course. Also, there are some nice options for the logcat util to ask for a one-time output or a tail or a full dump of system messages, etc. (use logcat -? to see those)

- if you were rooted, I would suggest viewing the kernel log (cat /proc/kmsg)...

- if this is your Java program, you could instrument it with key displays at critical function points...

Otherwise, not sure if there is a way to tell Java to output/display current state/status...run-time options?

Maybe the strace utility? (not sure if that requires root or not)

That's all I have for now...wish I had something concrete for you...
 
Thank you much anyway. at least I can look for a different approach now. I will try to limit resource usage from within the software and see how effective that is.

If anyone could confirm weather or not the cpulimit command works on a rooted device I would like to hear it.
 
Thank you much anyway. at least I can look for a different approach now. I will try to limit resource usage from within the software and see how effective that is.

If anyone could confirm weather or not the cpulimit command works on a rooted device I would like to hear it.

No problem :).

I'll charge-up my test, rooted Nexus 5 and see if I have the cpulimit command and how it behaves with and without root.
 
Back
Top Bottom