R
Roy Johnson
I've got a program that I want to be the only instance of itself
running at any given time. The method I've chosen for doing that is
probably not the preferred method, and it certainly won't work under
Windows.
Here's what I'm doing:
### Ensure that this is the only instance running
my @myprocs = grep(/perl $0/, `ps -f`);
for (@myprocs) {
my ($pid) = (split)[1];
next if ($pid == $$);
die "Found $_\n";
}
What *should* I be doing, for maximum reliability on both Unix and
Windows?
running at any given time. The method I've chosen for doing that is
probably not the preferred method, and it certainly won't work under
Windows.
Here's what I'm doing:
### Ensure that this is the only instance running
my @myprocs = grep(/perl $0/, `ps -f`);
for (@myprocs) {
my ($pid) = (split)[1];
next if ($pid == $$);
die "Found $_\n";
}
What *should* I be doing, for maximum reliability on both Unix and
Windows?