如何通过在 Linux 上使用 C、C++ 指定其名称来以编程方式检查特定守护程序是否正在运行?
A simple command to run would be systemctl status ${service} | grep "Active:" | cut -d' ' -f6
systemctl status ${service} | grep "Active:" | cut -d' ' -f6
systemctl status ${service} | grep "Active:" | cut -d' ' -f6
. Capture the stdout of the above command and it should equal (running)
.
On that note, *ctl
are intended for command line use only and not for use by other programs. The accepted way is to interact with systemd
using the dbus
API.
As I cannot add comment above. you can use systemctl to check service status.
systemctl status servicename
This is terminal command. using system("systemctl status servicename")
u can manage call from c++.
Hope this is what is were looking at or similar.
systemctl is-active ${service_name} 可用于检查服务是否处于活动状态
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.