Query if service is running
문제
How can I query if a service (dnsmasq) is running, in C?
해결책
According to the dnsmasq man page, by default it writes a pid file to /var/run/dnsmasq.pid
. This file will be a text file that contains an integer representing the process ID. Open the file, read the integer, and call kill(pid, 0)
to see whether the process is alive at that pid. (Although checking for PID existence isn't guaranteed to not find some other process running at that PID, it's usually good enough.)
제휴하지 않습니다 StackOverflow