Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
All,
There are a number of non-perfect solutions to running only 1 instance of a process at a time. The common solutions are pid files, lock files, checking the process table - or some combination. The trouble with most of them is that they are not bullet proof (you can delete a locked file for instance). Dominus published a presentation on File Locking Tips and Traps back in 2003. One of the suggested solutions was to lock the file of the running process itself:
There are a number of non-perfect solutions to running only 1 instance of a process at a time. The common solutions are pid files, lock files, checking the process table - or some combination. The trouble with most of them is that they are not bullet proof (you can delete a locked file for instance). Dominus published a presentation on File Locking Tips and Traps back in 2003. One of the suggested solutions was to lock the file of the running process itself:
In the few instances I have needed this, one of these have worked. Recently I suggested a co-worker improve his code by using one of these techniques and he told me neither worked on AIX. The error in both cases is "unable to lock: A file descriptor does not refer to an open file."open SELF, "< $0" or die ...; flock SELF, LOCK_EX | LOCK_NB or exit; or flock DATA, LOCK_EX | LOCK_NB or exit; ... __DATA__
Does anyone have any insight into why this is or have any suggestion on an alternative lightweight and nearly bullet proof way to accomplish the original objective?
Cheers - L~R
|
---|
Back to
Seekers of Perl Wisdom