Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl process

Status
Not open for further replies.

lmiu

Programmer
Jan 25, 2006
16
GB
Hi, please can anyone help me. I have a Perl script running, its used for processing some files in batch.
Is there any script or ways that when I add in to the Perl script to check if theres a process currently running, if so die. So that hopefully the Perl script wouldn't try to process multiple files at once.


Thanks in Advance
 
One way would be to check for a lock file on your system which the script would create if there wasn't one already. Something like the following:

Code:
#!/usr/bin/perl

use strict;

my $lock_file = '/dir/to/lock.file';

if (-e $lock_file) {
    print qq(Lock file already present.  Ending script.);
    exit;
}

open (LOCK, ">$lock_file") or die "Cannot create lock file: $!';
print LOCK qq( );
close (LOCK) or die "Cannot close lock file: $!";

##Process starts here

unlink ($lock_file) or die "Cannot unlink lock file: $!";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top