【问题标题】:How to detect when dbus app exits or craches?如何检测 dbus 应用程序何时退出或崩溃?
【发布时间】:2015-12-22 20:36:59
【问题描述】:

当使用的 dbus 服务退出/崩溃/重新启动时,dbus 用户如何获得通知?

本教程建议有一种方法可以做到这一点,但在规范中我只找到了一个用于名称所有者的信号。

dbus tutorial 说: Names have a second important use, other than routing messages. They are used to track lifecycle. When an application exits (or crashes), its connection to the message bus will be closed by the operating system kernel. The message bus then sends out notification messages telling remaining applications that the application's names have lost their owner. By tracking these notifications, your application can reliably monitor the lifetime of other applications. dbus specification 有一个关于 NameLost 信号的部分: org.freedesktop.DBus.NameLost This signal is sent to a specific application when it loses ownership of a name.

【问题讨论】:

    标签: dbus


    【解决方案1】:

    找出这一点的一种方法是侦听org.freedesktop.DBus.NameOwnerChanged 信号,如D-Bus specification 中指定的那样

    您的客户端需要实现一些逻辑来分析信号的参数,以确定名称何时被声明、服务何时重新启动、服务何时消失等。但上述信号可用于接收至少相关信息。

    在您的处理函数中,您可以检查name 参数是否与您想知道的服务名称匹配。如果old_owner 参数为空,则服务刚刚在总线上声明了该名称。如果new_owner 为空,则服务已离开总线(无论出于何种原因)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      相关资源
      最近更新 更多