简体   繁体   English

如何在QT中通过C ++监控Linux中的服务?

[英]How to monitor a service in Linux via C++in QT?

I'm working on a small app to test waters in C++ using QT Creator on a Ubuntu box. 我正在开发一个小应用程序,在Ubuntu盒子上使用QT Creator在C ++中测试水域。

Here's the deal, I wanted to Start/Stop a certain service and as well monitor it's status in case it is started/stopped outside my app. 这是交易,我想启动/停止某项服务,并监控它的状态,以防它在我的应用程序之外启动/停止。

I got the first part covered which is starting/stopping the service using QProcess . 我得到了第一部分,它使用QProcess启动/停止服务。

While reading about the QProcess I came accross this but unfortunately I can't make much sense of it to implement it. 在阅读关于QProcess我遇到了这个问题,但不幸的是,我无法理解它的实现方式。

I'd really appreciate some help here. 我真的很感激这里的一些帮助。

Regards, 问候,

Starting / Stopping services on a Linux box is best done via its service management interface and not via QProcess . 在Linux机器上启动/停止服务最好通过其服务管理界面而不是通过QProcess Given that your project is new, I would not try to support Ubuntu proprietary service manager (Upstart) and instead build support for systemd that will replace it in the near future. 鉴于您的项目是新的,我不会尝试支持Ubuntu专有服务管理器(Upstart),而是建立对将在不久的将来取代它的systemd的支持。

First you need to install systemd. 首先,您需要安装systemd。

https://askubuntu.com/questions/420917/how-can-i-replace-upstart-with-systemd https://askubuntu.com/questions/420917/how-can-i-replace-upstart-with-systemd

Then try out this C++ library: 然后试试这个C ++库:

https://github.com/ilpianista/libsystemd-qt https://github.com/ilpianista/libsystemd-qt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM