in reply to flock(), dodgy return?

Also see Highlander - allow only one invocation at a time of an expensive CGI script - even though it's geared towards CGI, it's likely what you want, if you want only one instance of the script running at the same time...