I was not at all clear with my post .
I thought I could use flock on -unless-
to prevent a race condition.
since the code is in between the opening and closing of the
semaphore file. I can not figure out a different way to check if a file exist and write to it ,so it is not possible