# Check if the program is running or died unexpectedly if (-e $PIDFile) { print "Error: $0 is still running."; # Here you can gracefully remove the process or just kill # it using a SIGNAL or kill this process and let the # original one run } else { open (PID, '>',$PIDFile); print PID $$; close (PID); }