c++ - 对 `sd_notify' 的 undefined reference

标签 c++ linux ubuntu notifications

我有一个创建很多进程的进程,我想识别(获取 pid)其中一个 child 。遍历子项会占用大量资源(不要问为什么)。所以我试图通过(以某种方式)识别它是否使用 sd_notify 来获取进程的 pid 并获取 pid(如果可能的话,我现在真的不知道)。我正在使用 ubuntu 14.04 并创建了一个小测试程序:

#include <systemd/sd-daemon.h>
#include <stdio.h>

int main()
{
  int a;
  a = sd_notify(0, "READY=1");
  printf("%d -> \n", a);
  fflush(stdout);
}

但它给了我错误提示 undefined reference to 'sd_notify'

附言 我发现 sd_notify 适用于 systemd 系统。在 upstart 系统中,这相当于什么?或者如何确保我正在搜索的进程不使用此功能?或者是否可以使用 sd_notify 记录进程发送的所有消息?

最佳答案

尝试安装 libsystemd-daemon-devel 然后使用

编译

g++ -o sig sig.cpp -lsystemd-daemon

关于c++ - 对 `sd_notify' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38302883/

相关文章:

linux - 如何搜索多个pdf文件的内容并返回pdf的文件名?

linux - 将应用程序嵌入到窗口中

linux - 装载点不存在,即使文件夹存在。可以手动挂载

linux - SSH 连接被远程主机关闭

ubuntu - 无法将 redis 作为守护进程运行... ubuntu 服务器,redis 2.6.0

c++ - int ** 与 int [ROWS][COLS]

c++ - 寻找 Java Graphics 替代品

c++ - 为什么 RH 编译程序的大小是 Ubuntu 编译程序的 4 倍

c++ - 字符串赋值困惑

c++ - 你可以用数字开始一个类名吗?