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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With