Pathologically Eclectic Rubbish Lister | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
How can I prevent more than one instance of a script from running? Lockfiles! I have at times used a lockfile but there is always the risk that the power could go off or some other catastrophe could occur between the lockfile being created and being removed. So is there a better way to do it? It's not necessarily the presence/absence of the lockfile that matters but rather the lock on that file. Locks don't persist through reboots so that problem is solved. See eg. the FAQ How can I lock a file? Another file-based approach is a PIDfile. You store the PID of the running process in the file and on subsequent runs check that that PID does not exist (or doesn't relate to the process you are running). Still use locks on the PIDfile during access to avoid race conditions, of course. 🦛 In reply to Re: Preventing multiple instances
by hippo
|
|