P is for Practical | |
PerlMonks |
Re^2: Mechanism for ensuring only one instance of a Perl script can only run?by afoken (Chancellor) |
on Dec 04, 2022 at 18:42 UTC ( [id://11148552]=note: print w/replies, xml ) | Need Help?? |
You could use a pid file for that. This is, as far as I know, the mechanism commonly used by server software. Um, yes, but that still has race conditions AND problems with reboots AND problems with programs crashing before they can remove their PID file. In short, PID files suck. Many people believe they are needed or at least useful, but they aren't. They were never a good idea, but nobody had a better solution for years. The better approach for managing service software is to have a monitoring process. AFAIK, djb's deamontools are the earliest solution for getting rid of PID files, and many other solutions copied that idea, including systemd. Yes, systemd may still create PID files for legacy reasons, but like with deamontools, they are no longer needed. For the Highlander problem ("there can be only one"), a PID file might work often, but there is no guarantee that it will always work. On Unix systems (Linux, BSD, ...), getting a lock on the executable is the most robust solution, as long as you stay away from non-native and networking filesystems. See Re^2: Mechanism for ensuring only one instance of a Perl script can only run?. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
In Section
Seekers of Perl Wisdom
|
|