in reply to Replacing a string in a file

I also presume that to give your program exclusive access to the file you have also locked it using the flock command.
flock( NAMEGET, 2 );
You can use the value 2 to lock and change to 8 after you have done the modification to remove the access.