Good question :), now I have exactly the same. I am not sure if this is the correct answer, but I hope this helps, and I am also grateful for the feedback.
I searched googled and found that registering each daemon user as a dbus service is an elegant solution. dbus can verify that the service only works once. no need for pidfile.
Another solution (my current) would be to create a PID file in a directory, for example:
$HOME/.yourdaemon/pid
After your comment, I realized that you cannot write at home. I would suggest studying dbus
Update
I have an idea. What if you use / tmp but look for a pidfile called yourdaemon.pid.UNIQUE_KEY and belongs to the daemon user? This should work fine.
UNIQUE_KEY must be randomly generated (it is preferable to use tempnam, since it is a proof of race conditions).
hek2mgl
source share