RE: how to make sure, that the script is running one time?

From: Bob Showalter (Bob_Showalter_at_taylorwhite.com)
Date: 03/12/04


To: "'stalp@imbei.uni-mainz.de'" <stalp@imbei.uni-mainz.de>,  beginners@perl.org
Date: Fri, 12 Mar 2004 10:32:36 -0500

Christian Stalp wrote:
> Hello together,
> I have a question regarding process-control. I want to write a perl
> script which must not running in more than one process in the same
> time. The script creates a directory copys a zip-file in it, unpack
> it and reads every file in this package. However, the files must not
> get opened by another process.

Are you extracting the files just to read through them? Why not just extract
to a pipe and read the data from that? Then you can avoid creating the files
in the first place?

> How can I make sure, that my perl-scipt runs only in one process

This is typically done by acquiring a lock on a file (usually a "pid" file
that contains the process id number). There's a Proc::PID::File module on
CPAN that looks pretty neat, though I haven't used it personally.

> , or
> eaysier, is there a function "flock" which blocks a whole directory
> and not only a single file?

Not really a way to do that with a lock, and locks are "advisory" only,
depending on your O/S. You might want to play with directory permissions...



Relevant Pages

  • Re: File Locks...
    ... E.G. firewalls logs can be "copied" while in use when using ... You could autostart a wbem script to monitor file change in a dir ... > remove a file lock condition. ...
    (microsoft.public.scripting.wsh)
  • Re: I cant flock, it returns 0, any ideas.
    ... # returns zero when I try to flock ... >> I wanted to run this script to see if it would affect my other perl ... If someone holds a LOCK_EX lock, all attempts to get a lock will ... > the flock call will fail, and if you don't flock will just not ...
    (comp.lang.perl.misc)
  • Re: [PHP] Individual bulk e-mails - performance question (was "skinning a cat") :-)
    ... I assume it is simply creating a shell script like Jochem wrote, ... Create a PHP file that holds some lock code which is triggered by ... get all entries with that session ID ...
    (php.general)
  • Re: File concurrancy question
    ... >comes the cron job to print it. ... into the script which creates the file in the first place, ... a lock on the file before it may print. ... Unix doesn't enforce proper behaviour. ...
    (comp.os.linux.development.system)
  • Re: Prevent multiple instances of a script to launch
    ... I have written a Perl script and use it to drag&drop files on it ... Now if I drop multiple files at once, they are processed one after the ... The standard method is for the program to acquire an exclusive lock ... You'll need some form of IPC to transmit requests to the server. ...
    (comp.lang.perl.misc)