My first thought was to write a file to disk (a lock) and remove it on exit - so the next process will know to die... but what happens if it quits (or is killed) without removing the lock? Then nothing runs...
When a process dies, the OS removes any and all flock locks placed by it. Instead of checking for the existance of a lock file, check if there's a lock on it (after unconditionally creating the file).
Checking for existance is flawed anyway. For example,
Process 1 Process 2
----------------------------- -----------------------------
die if -e $lockfile;
die if -e $lockfile;
open(my $fh, '>', $lockfile);
# I think I hold the lock.
open(my $fh, '>', $lockfile);
# I think I hold the lock.
.
.
.