gpt4 book ai didi

ios - StartInterval 键如何影响启动的守护进程

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:50 35 4
gpt4 key购买 nike

我有一个作为守护进程运行的应用程序。我把application plist放在iOS 8设备的/Library/LaunchDaemons下,然后通过执行命令启动它

launchctl load /Library/LaunchDaemons/com.mycompany.testapp.plist

在我的 laumchd plist 中,注意应用程序通过执行命令作为守护进程运行

我想让这个应用程序只有在崩溃或被杀死时才重新启动。如果我故意用代码 0 退出它,我不希望它重新启动。我试过以下配置。这在 iOS 7 上有效,但在 iOS 8 上无效。

<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<true/>
</dict>

因此我尝试添加另一个设置为 10 的键 StartInterval

<key>StartInterval</key>
<integer>10</integer>

我通过使用代码 0 退出并使用命令 kill -9 [PID] 终止我的应用程序来测试这个场景。此 key 使我的应用程序在被杀死后 10 秒后再次启动。但是,在我的应用程序运行时,我担心这个键的结果。

这个 key 对启动和运行的应用程序有影响吗?我监视了日志,似乎 StartInterval 键对正在运行的守护进程没有任何作用。但是,我对此不太确定。你能解释更多关于它的信息吗?非常感谢。

最佳答案

根据此链接http://pitaya.ch/documentation/iOS8_0APIDiffs.html header 中 launchd 的所有痕迹都消失了。 (搜索 /usr/include/launch.h,所以您会看到它已被删除)似乎是因为移动到新的 libxpc 作为 launchd 的基础(参见 http://technologeeks.com/docs/launchd.pdf 中的最后一张幻灯片)。

似乎他们改变了 iOS 8 中的 launchd 行为。Apple 自己的 LaunchDaemons(位于 /System/Library/LaunchDaemons/ 下)有些也有 KeepAlive - 字典格式的属性。如果你杀死它们,它们会立即通过 launchd 重生。

但经过一些测试后,让 KeepAlive 属性正常工作的唯一方法是添加 LaunchEvents(请参阅 http://technologeeks.com/docs/launchd.pdf 中的幻灯片 21ff)和/或 MachServices 到 plist 或将 KeepAlive-property 更改为:

<key>KeepAlive</key>
<true/>

但是除了执行 launchctl unload/Library/LaunchDaemons/com.mycompany.testapp.plist 之外,没有办法在没有 launchd 重生的情况下杀死你的守护进程。

我的工作列表:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Program</key>
<string>/path/to/your/daemon</string>
<key>RunAtLoad</key>
<true/>
<key>Label</key>
<string>com.mycompany.testapp</string>
<key>EnablePressuredExit</key>
<false/>
<key>UserName</key>
<string>root</string>
<key>JetsamProperties</key>
<dict>
<key>JetsamPriority</key>
<integer>-49</integer>
<key>JetsamMemoryLimit</key>
<integer>10000</integer>
</dict>
<key>POSIXSpawnType</key>
<string>Adaptive</string>
<key>Disabled</key>
<false/>
<key>ThrottleInterval</key>
<integer>5</integer>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
<key>Crashed</key>
<true/>
</dict>
<key>MachServices</key>
<dict>
<key> com.mycompany.testapp.someMachService</key>
<true/>
</dict>
<key>EnableTransactions</key>
<false/>
<key>LaunchEvents</key>
<dict>
<key>com.apple.notifyd.matching</key>
<dict>
<key>SignificantTimeChangeNotification</key>
<dict>
<key>Notification</key>
<string>SignificantTimeChangeNotification</string>
</dict>
<key>SomeMoreNotifications</key>
[...]
</dict>
</dict>
</dict>
</plist>

关于 StartInterval-property:除了 KeepAlive-property 之外,甚至 Apple 也有这个属性用于一些重要的守护进程(例如 com.apple.locationd),它们似乎运行得很好。所以我认为您不必担心...

关于ios - StartInterval 键如何影响启动的守护进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26627227/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com