How can I query if a service (dnsmasq) is running, in C?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 callkill(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.)