Analysis of the function of Linux Sync command

Source: Internet
Author: User

After the sync command starts the UNIX system with the reboot command, the system prompts for an error message, and some applications do not work correctly.  After careful examination of the system files, and compared with the initial correct backup, found that some files are really destroyed, and can not find the cause of the file corruption, and finally think of the write Cache command--sync, before reboot run Sync command, causing the system file changes and does not work properly. The function of the Www.2cto.com Sync command is to send the memory resident information about the file system into the physical medium. Before pausing the system, such as restarting the machine, be sure to perform the sync command. UNIX system operating experience shows that to ensure reliability, the two-pass sync command should be performed because the Sync command does not guarantee that the information is actually written to disk, although it has been executed once. After the sync command is executed, wait for the disk work light to go out (assuming there is a system operating light), and then to actually pause the machine or start the machine. The destruction of a UNIX system is something that can happen at any time, so be sure to run the sync command before starting the machine or shutting down the machine. Remember that in any case, careful execution of the sync command will never do any harm www.2cto.com umount time is too long, the use of the Sync command has a problem, such as CP a file to the SD card, is not first write this file to the SDRAM, And then umount the contents of SDRAM to really write on the SD card?  I'm going to be umount for a while. Terminal prompt, based on the size of the write file to determine the umount time? Later check the information, Linux file System update is a complex process, when the user program to modify the file system, such as write operations, file data changes in the kernel buffer, when the data is not written to disk, can still execute the user process, All data changes are reflected in the contents of the inode. The data update for the disk is actually asynchronous, and it is likely that the data for the disk is actually updated after the write operation has been completed for a long time.

The sync command forces all data that is buffered by the disk to be written to disk, and if the system is terminated before the disk buffers are written to disk, the disk's file system is in an unstable state. In normal mode, even if the partition is not umount, the system calls the Sync command to force the disk to write all the data buffered to disk before restarting, and in the first aid mode, the mounted partition must be umount. The system will only call the Sync command to force all disk buffering data to disk, please note this issue in the first aid mode of the friend. In fact, "reboot-n (Don ' t sync before reboot or halt)" does not use the Sync command to force all disk-buffered data to disk before restarting, which is a good indication of the problem.  www.2cto.com   So to perform the sync command after CP finishes writing the contents of the buffer to the disk, and then Umount will not show the delay .  experience, using this method, delay write problem can solve

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.