Analysis on the functions of Linux sync commands

Source: Internet
Author: User


After the Sync command starts the unix system with the reboot command, the system prompts an error message. Some applications cannot work normally. After carefully checking the system files and comparing them with the initial correct backup, we found that some files were indeed damaged and we could not find the cause of the file being damaged, finally, I thought of writing the cache command-sync. I didn't run the sync command before reboot, which led to changes in the system file and failed to work normally. The function of the "www.2cto.com sync" command is to send the memory resident information of the file system to the physical media. Before suspending the system, for example, restarting the machine, you must execute the sync command. The Running Experience of unix systems shows that the sync command should be executed twice to ensure reliability, because the information is not actually written to the disk when the sync command is completed, this command has been executed once. After executing the sync command, wait until the disk work light is off (assuming there is a system work indicator light), and then stop the running of the machine or start the machine. A unix system can be damaged at any time. Therefore, you must run the sync command before starting or shutting down the machine. Remember that under no circumstances can you exercise caution when executing the sync command? www.2cto.com umount takes too long. There is a problem with the use of the sync command, for example, cp a file to the SD card, do you need to write the file to the SDRAM first, and then write the content in the SDRAM to the SD card when umount? When I use umount, the terminal prompt will appear too long. How long is the umount time determined based on the size of the written file? Later, I checked the information. Linux file system update is a complicated process. After the user program modifies the file system, for example, a write operation is performed, file data records modifications in the kernel buffer. when the data is not written to the disk, the user process can still be executed. All data changes are reflected in the inode content. The disk data is actually updated asynchronously. It is very likely that the disk data will be updated after the write operation is completed for a long time.

The sync Command forces all data cached on the disk to be written to the disk. if the system is terminated before the disk buffer information is written to the disk, the file system of the disk is in an unstable state. In normal mode, even if no umount operation is performed on the partition, the system will call the sync command to forcibly write all data cached on the disk to the disk before the restart, in emergency mode, the system must perform the umount operation on the mounted partition before calling the sync command to forcibly write all data cached on the disk to the disk, please pay attention to this problem in emergency mode. In fact, the "reboot-n (Don't sync before reboot or halt)" command does not require the sync command to forcibly write all the data cached on the disk to the disk before restart, which can easily explain the problem. Www.2cto.com. Therefore, after cp is complete, run the sync command to write the buffer content to the disk, and then umount will not be delayed. it has been verified that using this method, the problem of delayed writing can be solved from loongene's blog

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.