Detect when a USB device is connected in C

13,252

Look into udev documentation for this (writing udev rules).

Also have a look at this stackoverflow thread.

Share:
13,252
Admin
Author by

Admin

Updated on June 22, 2022

Comments

  • Admin
    Admin almost 2 years

    I am new to C and am trying to write a program that syncs files on my computer to a USB device. It currently works my me cd'ing to the directory that the device mounts to and typing "myprog init" which creates a .myprog file. The idea then is that when a USB device is connected my program checks for the .myprog file, if it finds it then it syncs. Problem is that I can't figure out how to detect when a new USB device is connected.

    I am writing the program for Linux (I'm using Ubuntu 9.04) and using GCC.

    Thanks for any help :)