http://www.perlmonks.org?node_id=478848


in reply to Writing a Perl Daemon

A) Super Search for daemon will find some nodes on writing perpetual "background" processes. There are some fiddly bits to look after, but Proc::Daemon will do a fine job of that for you.

B) A convenient way of using a lockfile is with sysopen;

sysopen my $fh, '/var/lock/mydaemon', O_EXCL | O_RDWR or die "$0 is already running";
You should ensure that you call unlink '/var/lock/mydaemon'; in every exit path your code may take.

After Compline,
Zaxo