lock is for variables (when using threads). You want flock (or File::Flock, IO::File::flock).
In reply to Re: logging of process by Anonymous Monk in thread logging of process by sandy1028