> Generally, it's not a good idea to keep file locks for a longer period > of time... YOu should really just take them while you write a file, and > then release them, but not keep them forever...
I keep the lock on the pidfile as long as the daemon is running. I think this is the best way to prevent a second daemon from running in parallel: If the first instance of your program just writes the pid into the pidfile and the second instance reads it and checks if this pid is alive, the first instance could have died ages ago and the pid was reused by another program. Or if the whole system crashes and is rebooted, another program could have been issued the same pid as the daemon had before. So the new instance won't start. By using the lock I can make sure that this can't happen as the lock will be removed when the first instance dies or the system is rebooted. I don't want to rely on systemd for all that because the program must work reliably on platforms without systemd too. > systemd expects that binaries forked off with ExecStart= (if you use > Type=forking) or ExecReload= return only after the new daemon is fully > up and the PID file is written. Thanks for pointing this out. Will add some logic to ensure this. Kind regards, Gerd _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel