if ( lockfile_exists() ) { warn script_is_locked(); exit 1; } $SIG{'__DIE__'} = \&remove_lockfile(); lock_file(); do_stuff(); remove_lockfile(); exit;