Heavily tested, but simple filelocking solution using flock command.