#!/usr/bin/perl -w use strict; open(EXCLUSIVELOCK, ">/tmp/$0.lock"); flock(EXCLUSIVELOCK, LOCK_EX); # If we reach this point, we have exclusive lock # The rest of the code goes here, immediately before # terminating, you can release the lock flock(EXCLUSIVELOCK, LOCK_UN);