Linux file system is asynchronous, that is to write a file is not immediately saved to the media (hard disk, u disk, etc.), but stored in the buffer, and so accumulated to a certain extent and then saved to the media.
Linux file system is asynchronous, that is to write a file is not immediately saved to the media (hard disk, u disk, etc.), but stored in the buffer, and so accumulated to a certain extent and then saved to the media. If there is no umount illegally pull U disk, the program is not known, fopen,fwrite and other functions are still returned to the correct, know the operating system to write media, will be prompted I/O error. But a lot of data will be lost because of this inaccurate report.
In fact, the USB driver changes the system configuration file when it is plugged in and unplugged.
For example, U disk driver will be inserted or unplugged to/proc/scsi/usb-storage-0/0 inside the Attached:yes or No
By looking at this file it is not difficult to detect whether the U disk is plugged in or unplugged.
Note: U disk is inserted in the state and whether the mount (Mount) has nothing to do