in reply to Determining if self is already running under WinNT/2000

Here's a simple example using Win32::Mutex, a standard module (mutex is short for mutual exclusivity). Save it as mutex.pl and try to run it twice or more. The second instance will die.

#!/usr/bin/perl use strict; use warnings; use Win32::Mutex; my $mutex = Win32::Mutex->new(1, 'mutex.pl'); my $return = $mutex->wait(0); die "already running" unless $return; while (1){ exit if <> }

theorbtwo is right that it's not portable - but it is the "Windows®" way of doing this.

Replies are listed 'Best First'.
Re: Re: Determining if self is already running under WinNT/2000
by Anonymous Monk on Feb 06, 2003 at 23:38 UTC
    The Win32::Mutex does work on my release of perl. I will have to readup on what this module does, Thanks!!! I am still interested in gaining access to the command line arguments of perl. The information has to be in there somewhere because the NT Resource Kit utilities tlist.exe lists it... C:>tlist.exe 2084 CMD.EXE Command Prompt c:\bin\perl.exe c:\src\prg.pl
        Here is the version info...

        C:\SRC\perl>c:/activeperl/bin/perl.exe -version

        This is perl, v5.6.1 built for MSWin32-x86-multi-thread
        (with 1 registered patch, see perl -V for more detail)

        Copyright 1987-2001, Larry Wall

        Binary build 633 provided by ActiveState Corp.
        http://www.ActiveState.com
        Built 21:33:05 Jun 17 2002