Method of detecting whether U disk is connected on Linux system

Source: Internet
Author: User
Tags file system linux
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



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.