A few solutions come to mind.
My suggestions here tend to be "stepping around"
the problem instead of actually fixing it:
- make the back-end executable responsible for removing the
temporary files.
- You can unlink the temp file as soon as the "back-end process"
has opened it and everything should work properly. You
don't need to wait for the back-end process to complete (unless
it does something funky like open the file multiple times).
See the earlier discussion on
Avoiding a Race Condition
for more details about the "deleting an opened file" technique.