Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query if service is running

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

like image 630
Delan Azabani Avatar asked Jan 28 '26 06:01

Delan Azabani


1 Answers

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

like image 125
Greg Hewgill Avatar answered Jan 29 '26 20:01

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!