如何让原生C可执行文件在Android中永久运行?
有没有办法让原生 C 可执行文件在 Android 操作系统中永远运行(在后台)? 我在Android中移植了libpcap并制作了一个嗅探器。我有一个已 root 的 HTC Hero。我通过以下命令在后台运行嗅探器:
$ su
# mount -o remount,rw -t vfat /dev/block//vold/179:0 /sdcard
# /sdcard/mysniffer &
我同时运行一个 Android 服务,以循环方式浏览网页列表。为了强制我的服务在后台永远运行,我获取了 PARTIAL_WAKE_LOCK通过 android.os.PowerManager。
该服务在后台永远运行,但运行一段时间后,嗅探器会从操作系统中终止。
有没有办法让它永远运行?我希望这两个程序始终在后台运行,以便进行一些测量。
Is there a way to make a native C executable run forever (in background) in Android OS?
I have ported libpcap in Android and I made a sniffer. I have a rooted HTC Hero. I run the sniffer in the background through this commands:
$ su
# mount -o remount,rw -t vfat /dev/block//vold/179:0 /sdcard
# /sdcard/mysniffer &
I simultaneously run an Android service that browses a list of web pages in a loop fashion. To force my service run forever in the background I acquire a PARTIAL_WAKE_LOCK via android.os.PowerManager.
The service runs forever in the background but the sniffer is killed from the OS after some time of running..
Is there a way to make it run forever? I want both of these programs running always in the background so as to do some measurements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一种方法来做到这一点,并进行了我的实验和测量! :) 我刚刚用PARTIAL_WAKE_LOCK “http://developer.android.com/reference/android/os/PowerManager.html#SCREEN_DIM_WAKE_LOCK” rel="nofollow">SCREEN_DIM_WAKE_LOCK 在我的服务中!
我无法理解原因,但是通过这样做,本地嗅探器不会被杀死
Android..如果有人知道更好的解决方案,请告诉我们。
I found a way to do this, and conduct my experiments and measurements! :) I just changed the PARTIAL_WAKE_LOCK with a SCREEN_DIM_WAKE_LOCK in my service!
I can't understand the reason, but by doing this the native sniffer is not killed by
Android.. If someone knows a better solution, please let us know.