I am currently working on a linux daemon which should be a single instance (i.e. limited to one process 1 user 1). What would be the best way to do this without using getpid()to manually write the pid to / var / run / and then block it with flock()?
getpid()
flock()
Just lock the executable file.
Enable startup and shutdown using start-stop-daemon .
libunique. .
- initd, . COMMAND ,
PIDFILE=/var/run/service.pid COMMAND="java -jar start.jar" $COMMAND > /dev/null 2>&1 & echo $! > $PIDFILE
@dogane, .
If you really don't have a lock file, use a socket instead. Another instance will not be able to start because the address will already be used.