Question

How can I query if a service (dnsmasq) is running, in C?

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top