Code Comments
Programming Forum and web based access to our favorite programming groups.I have a perl program that launchs every minutes using a Windows Task Scheduler to process some files. If the Perl program is still running, I don't want to run it again until the previous Perl application has finished. It is possible to detect whether or not my Perl application is already running?
Post Follow-up to this messageTom Tingdale <tom.tingdale@sbcglobal.net> wrote in news:cntqn0ljli76jgit7sel1hjk9om7e6co4m@ 4ax.com: > I have a perl program that launchs every minutes using a Windows Task > Scheduler to process some files. If the Perl program is still running, > I don't want to run it again until the previous Perl application has > finished. It is possible to detect whether or not my Perl application > is already running? One relatively more portable way is to use lock files. See perldoc -q lock You can also try Win32::Process::Info: http://search.cpan.org/~wyant/Win32...o-1.002/Info.pm Sinan.
Post Follow-up to this messageTom Tingdale <tom.tingdale@sbcglobal.net> wrote in message news:<cntqn0ljli76jgit7sel1hjk9o
m7e6co4m@4ax.com>...
> I have a perl program that launchs every minutes using a Windows Task
> Scheduler to process some files. If the Perl program is still running,
> I don't want to run it again until the previous Perl application has
> finished. It is possible to detect whether or not my Perl application
> is already running?
sub runUpdate{
my $pi = Win32::Process::Info->new();
my $Updates = 0;
foreach $proc ($pi->GetProcInfo())
{
foreach ($proc)
{
if ($proc->{Name} eq "update.exe")
{
#Count the number of running instances
$Updates++
}
}
}
# if no running update.exe found start it otherwise exit
if ($Updates <= 1)
{
doit();
}
else
{
warn "An instance of the Updater is running, exiting now.";
exit;
}
}
Post Follow-up to this messageThank you Bryan. I appreciate it!
Tom
On 25 Oct 2004 22:51:45 -0700, bitbucketz2002@yahoo.com (Bryan
Williams) wrote:
>Tom Tingdale <tom.tingdale@sbcglobal.net> wrote in message news:<cntqn0ljli
76jgit7sel1hjk9om7e6co4m@4ax.com>...
>
>sub runUpdate{
> my $pi = Win32::Process::Info->new();
> my $Updates = 0;
>
> foreach $proc ($pi->GetProcInfo())
> {
> foreach ($proc)
> {
> if ($proc->{Name} eq "update.exe")
> {
> #Count the number of running instances
> $Updates++
> }
> }
> }
> # if no running update.exe found start it otherwise exit
> if ($Updates <= 1)
> {
> doit();
> }
> else
> {
> warn "An instance of the Updater is running, exiting now.";
> exit;
> }
>}
Post Follow-up to this messageThank you Bryan. I appreciate it!
Tom
On 25 Oct 2004 22:51:45 -0700, bitbucketz2002@yahoo.com (Bryan
Williams) wrote:
>Tom Tingdale <tom.tingdale@sbcglobal.net> wrote in message news:<cntqn0ljli
76jgit7sel1hjk9om7e6co4m@4ax.com>...
>
>sub runUpdate{
> my $pi = Win32::Process::Info->new();
> my $Updates = 0;
>
> foreach $proc ($pi->GetProcInfo())
> {
> foreach ($proc)
> {
> if ($proc->{Name} eq "update.exe")
> {
> #Count the number of running instances
> $Updates++
> }
> }
> }
> # if no running update.exe found start it otherwise exit
> if ($Updates <= 1)
> {
> doit();
> }
> else
> {
> warn "An instance of the Updater is running, exiting now.";
> exit;
> }
>}
Post Follow-up to this messagebitbucketz2002@yahoo.com (Bryan Williams) wrote in
news:38a10436.0410252151.6f7094a3@posting.google.com:
> Tom Tingdale <tom.tingdale@sbcglobal.net> wrote in message
> news:<cntqn0ljli76jgit7sel1hjk9om7e6co4m@4ax.com>...
>
> sub runUpdate{
> my $pi = Win32::Process::Info->new();
> my $Updates = 0;
>
> foreach $proc ($pi->GetProcInfo())
> {
> foreach ($proc)
> {
> if ($proc->{Name} eq "update.exe")
> {
> #Count the number of running instances
> $Updates++
> }
> }
> }
Huh? In Perl, one would do:
my $instances = grep { /^update.exe$/ } @{[ $pi->GetProcInfo()};
> # if no running update.exe found start it otherwise exit
> if ($Updates <= 1)
> {
> doit();
> }
Ahem, the criterion was to not start an update if update.exe was already
running. So, there should be no instances of 'update.exe' running.
However, this is neither here nor there. Since the operation of counting
the number of instances of update.exe in the process table is not atomic,
this code will not prevent two or more instances of update.exe from
running.
That is, an update process might be launched between searching the
process table for 'update.exe' entries, and the check on the number of
instances.
Sinan.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.