Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash after write in linux

Tags:

linux

What would happen if I were to use write() to write some data to a file on disk. But my application were to crash before flushing. Is it guaranteed that my data will get eventually flushed to disk if there is no system failure?

like image 898
pjay Avatar asked May 22 '12 10:05

pjay


People also ask

Why is my Linux crashing?

If you are running Ubuntu and your system randomly crashes, you may be running out of memory. Low memory could be caused by opening more applications or data files than will fit in the memory you have installed. If that is the problem, do not open so much at one time or upgrade to more memory on your computer.

How do I see crash logs in Linux?

Linux logs will display with the command cd/var/log. Then, you can type ls to see the logs stored under this directory. One of the most important logs to view is the syslog, which logs everything but auth-related messages.

What is the use of kdump in Linux?

kdump is a feature of the Linux kernel that creates crash dumps in the event of a kernel crash. When triggered, kdump exports a memory image (also known as vmcore) that can be analyzed for the purposes of debugging and determining the cause of a crash.

What is in VAR crash?

The /var/crash partition stores core files from running services that have crashed. It might also contain log gather data or temporary files created and stored by technical support or the customer.


1 Answers

If you're using write (and not fwrite or std::ostream::write), then there is no in process buffering. If there is no system failure, then the data will, sooner or later (and generally fairly soon) be written to disk.

If you're really concerned by data integrity, you can or in the flags O_DSYNC and O_SYNC to the flags when you open the file. If you do this, you are guaranteed that the data is physically written to the disk before the return from write.

like image 159
James Kanze Avatar answered Oct 04 '22 00:10

James Kanze