I am currently working on a linux daemon that needs to be single instance (i.e restricted to 1 user 1 process). What would be the best way of doing so without having to use getpid()
to manually write the pid out to /var/run/ and then lock it using flock()
?
A Pid-File is a file containing the process identification number (pid) that is stored in a well-defined location of the filesystem thus allowing other programs to find out the pid of a running script.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
Wrap the start-up and shut-down with start-stop-daemon.
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