Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Detecting a Process using Perl Win32
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?

Report this thread to moderator Post Follow-up to this message
Old Post
Tom Tingdale
10-26-04 01:56 AM


Re: Detecting a Process using Perl Win32
Tom 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.

Report this thread to moderator Post Follow-up to this message
Old Post
A. Sinan Unur
10-26-04 01:56 AM


Re: Detecting a Process using Perl Win32
Tom 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;
}
}

Report this thread to moderator Post Follow-up to this message
Old Post
Bryan Williams
10-26-04 08:56 AM


Re: Detecting a Process using Perl Win32
Thank 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;
>    }
>}


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Tingdale
10-28-04 01:56 AM


Re: Detecting a Process using Perl Win32
Thank 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;
>    }
>}


Report this thread to moderator Post Follow-up to this message
Old Post
Tom Tingdale
10-28-04 01:56 AM


Re: Detecting a Process using Perl Win32
bitbucketz2002@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.

Report this thread to moderator Post Follow-up to this message
Old Post
A. Sinan Unur
10-29-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:59 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.