Linux modified files are invalid after restart; Linux modified files are restored after restart; Linux sync command is important! ! !

Original address: https://blog.csdn.net/wzying25/article/details/105518179/

related articles

1、system(函数)----https://baike.baidu.com/item/system/15078602?fr=aladdin

2. Linux system function return value- https://blog.csdn.net/cheyo/article/details/6595955

3. System function return value and popen ---- https://www.cnblogs.com/crazy-machine/articles/5720076.html

 

Linux modified files are invalid after restart; Linux modified files are restored after restart; Linux sync command is important! ! !

Encountered phenomenon:

In order to automatically run the script on the linux arm development board, the /etc/profile is modified.

Then the development board is powered off and restarted,...it is invalid, and the scripts added by yourself cannot be run automatically. Check the file /etc/profile and found that the file has not been modified. The /etc/profile file is restored.

I searched for information on the Internet and found out that it turned out to be a sync problem.

In the Linux system, the data to be written to the hard disk is sometimes written to the filesystem buffer for efficiency. This buffer is a memory space. If the data to be written to the hard disk is stored in this buffer, and the system suddenly shuts down If it is powered on, the data will be lost. The sync command will force the data stored in the buffer to be written to the hard disk.

Therefore, remember that if you modify a file in a Linux system, you must remember to execute the sync command and execute it several times.

In addition, after writing the file, you need to call fsync to ensure that the file is written to the hard disk in time.

 

Supplement: linux synchronization IO: sync, fsync and fdatasync

Guess you like

Origin blog.csdn.net/xqhrs232/article/details/113372963