android 会杀死我以 root 身份运行的守护进程吗?
我有一个应用程序(有一部分)需要始终运行;它不是作为服务启动的,应用程序启动一个以 root 身份运行的守护进程(用 c 编写)。
Android 会杀死我以回收内存吗?它以 root 身份运行可以保护我免受这种情况的影响吗?如果没有,我该怎么做才能确保它永远不会死,如果死了,它会重新开始?
I have an app that (has a part that) needs to always run; it's not started as a service, the app starts a daemon (written in c) which runs as root.
Is android going to kill it on me to reclaim memory? Does it running as root protect me from this? If not, what can I do to ensure that it never dies and if it does, it starts again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的守护进程是纯本机应用程序(例如,通过系统的 inittab 启动),而不是在 APK 上下文中运行的应用程序,那么 Android 将永远不会杀死它。至少,在我的情况下,正是这种情况,我的守护进程唯一一次终止是在我修复 SIGSEGV 之前;)
If your daemon is a pure native application (for example, started through the system's inittab), not something running within the context of an APK, then Android will never kill it. At least, in my situation which is exactly this, the only time my daemon has ever terminated is just prior to my fixing a SIGSEGV ;)
我已经有一段时间没有使用 android 了,也没有使用 root 运行进程。但我确实相信,无论您的应用程序正在运行什么用户,Android 操作系统都可能会向其发出“停止”命令,然后如果内存确实变低,则可能会发出“终止”命令。我之所以这么说是因为与完整的 Linux 内核类似,如果它需要内存,它会找到一种方法来获取它。我有一部 HTC 手机,实际上我已经看到内核杀死 HTC sense 来获取 RAM,这实际上会重置手机。有多种方法可以设置应用程序何时启动,我相信您可以设置挂钩来说明应用程序何时应根据手机事件启动。类似于当手机收到 txt 时 txt 消息应用程序将如何启动,或者即使您在任务管理器中杀死该应用程序,闹钟应用程序仍然会响起。我相信你可以在应用程序 xml 配置中设置这些。
祝你好运!
I havent worked with android in awhile now, nor have I worked with root running process. But I do believe that regardless of what user your app is running, android OS might issue it a 'do stop' and then potentially a 'kill' command if memory does get low. The reason I say this is because similar to the full Linux kernel, if it needs memory, it WILL find a way to get it. I have an HTC phone and I have actually seen the kernel kill HTC sense to get RAM, which essentially resets the phone. There are ways to set when an app should be started, I believe you can set hooks that say when an app should be started based off of phone events. Similar to how a txt msg app will start when a phone receives an txt, or how an alarm app will still go off even if you kill the app in a task manager. I believe you can set these in the apps xml config.
Good luck!