![](/img/trans.png)
[英]How to check the System folders in windows programmatically using C/C++?
[英]How to programmatically check if particular daemon is runnning by specifying its name on Linux using C, C++?
如何通過在 Linux 上使用 C、C++ 指定其名稱來以編程方式檢查特定守護程序是否正在運行?
一個簡單的運行命令是systemctl status ${service} | grep "Active:" | cut -d' ' -f6
systemctl status ${service} | grep "Active:" | cut -d' ' -f6
systemctl status ${service} | grep "Active:" | cut -d' ' -f6
。 捕獲上述命令的標准輸出,它應該等於(running)
。
在這一點上, *ctl
僅供命令行使用,而不供其他程序使用。 公認的方法是使用dbus
API 與systemd
交互。
因為我無法在上面添加評論。 您可以使用 systemctl 檢查服務狀態。
systemctl status servicename
這是終端命令。 使用system("systemctl status servicename")
可以管理來自 C++ 的調用。
希望這是正在查看或類似的內容。
systemctl is-active ${service_name} 可用於檢查服務是否處於活動狀態
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.