# See if I am already running # $my_name was derived earlier from $0 # $pidfile is set up in the scripts headers if (-f $pidfile) { open PID, $pidfile; my $pid = ; close PID; print "read pid $pid\n" if $debug; open PROCS, "ps -ef |"; ; # loose the header while () { (undef, my $this_pid) = split; if ($this_pid == $pid) { print "pid in use $_\n"; # check this realy is us, not pid re-use by OS last unless /$my_name/; die "looks like an instance is already running, exiting\n"; } } } open PID, ">$pidfile"; print PID $$; close PID;