in reply to How to identify a file is in readonly mode

You can use flock, to grant EXCLUSIVE or SHARED access using LOCKs, but that implies that both uses flock. This my solve or not your problem... If you want to to use flock see this link too.
  • Comment on Re: How to identify a file is in readonly mode