OK, this question is actually a follow-up question from my previous one: What would happen if I abruptly close my script while it's still doing file I/O operations?
So it’s not possible to see an incomplete line written into a file whenever you force your script/program to quit, as the OS will do their job. But what if there’s a power failure, and the OS is just in the middle of appending one line such as “This is a test”(or even bigger strings) into a file, do I get an incomplete line appended or nothing appended or even worse, previous content lost? I’m really curious to know, and this kind of situation would definitely happen on the server side. Anybody can help me out?
Rule 1. There’s no magic. No guarantee. No assurance. Power failure means the circuitry passes through states that are outside their design tolerances. Anything could happen. No guarantees.
Possibly. There’s no magic. The I/O could include two physical blocks. One written, one unwritten.
Possibly. There’s no magic. The I/O buffer may not have been synced to the device.
Possibly. There’s no magic. A block write to the device could — during a power failure — fatally corrupt bits on the device.
“Definitely”? Nothing’s definite during an uncontrollable event like a power failure. Anything could happen.
There’s a really small possibility that the random scrambled bits could be the text of Lincoln’s Gettysburg Address and that’s what appears on the device.