So I should use some lock, or say log. And I should put this lock on the disk because after the process die there is nothing leave in memory. So I will try to write a log which content is the position I wrote in the working file. Every time before I write something to the working file, I will write the position into the log file. After the working file is closed, the log file should be empty. And every time when the program restart, it will check the log file first. If there is something in the log file, pick up the last position and begin the writing from the next position.
In fact what I said is something like the logical log in RDBMS. Is it ok?