How can i prevent a process (script) from suspending (freezing) in android?

I have a script which run a command after wait for some minute

#!/sbin/busybox sh
while true; do
sleep 3600;
sync;
sysctl -w vm.drop_caches=2;
done;

but this script will pause after some second as soon as android device goes to sleep. Each time the device wake up the script continue counting. How can i make this script that never suspend (freeze)? I also set -1000 to "oom_score_adj" to not kill by oom. Thank you


How do I prevent an Android device from going to sleep programmatically?
From the root shell (eg adb shell), you can lock with:

echo mylockname >/sys/power/wake_lock

After which the device will stay awake, until you do:

echo mylockname >/sys/power/wake_unlock 

With the same string for 'mylockname'.

Note that this will not prevent the screen from going black, but it will prevent the CPU from sleeping.

Note that /sys/power/wake_lock is read-write for user radio (1001) and group system (1000), and, of course, root.

So I guess your script would be:

#!/sbin/busybox sh
echo mylockname >/sys/power/wake_lock;
while true; do
sleep 3600;
sync;
sysctl -w vm.drop_caches=2;
done;
echo mylockname >/sys/power/wake_unlock;

reference
reference 1

链接地址: http://www.djcxy.com/p/91172.html

上一篇: 部署Android应用程序Qt 5.1

下一篇: 我怎样才能防止进程(脚本)在Android中暂停(冻结)?