in reply to Exec or system functions

This is an OS-specific question. The usual answers are to leave a file with a process ID laying around and variations of that. If the PID is still active, then the process must be too. Or grunge through some kinds of process listing looking for the name.

Another answer is to open/lock a file -- if it fails (for a specific reason) then someone else has the file open and locked: your other instance.

One way I like to do it is to bind a specific network port on localhost. You don't actually have to listen to the port, just bind it. Only one "process" can bind a port at a time. If you try to bind and it's already bound, then there's already an instance of you running. (Note: pick a good out-of-the-way port number...) It's a portable technique and almost foolproof.

Replies are listed 'Best First'.
Re: Re: Exec or system functions
by rchiav (Deacon) on Jul 16, 2001 at 05:49 UTC
    If it's an application that you can access with OLE, you could use something like this (which I use to either use an open instance of excel or create a new one..
    my $exl = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application');
    There's also some API call's.. but I've never used them with Perl. Here's the link to some VB code that will do what you're looking for. Now, you just have to figure out how to use that and Win32::API

    Hope this helps..
    Rich

    Whoops.. this was supposed to be a reply to the question.. not the first answer :)