LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to know a usb device is plugged in/out (https://www.linuxquestions.org/questions/linux-software-2/how-to-know-a-usb-device-is-plugged-in-out-316998/)

lordofring 04-25-2005 12:40 PM

how to know a usb device is plugged in/out
 
Hello,

My application needs to be notified when a usb device is plugged in/out. I know the file /proc/bus/usb/devices is changed whenever a usb device is plugged in/out. But how do I know the file is changed. May I use poll(() function to wait for the file changing? (I don't want to read the file every second to see the chaning.)

Thanks in advance.

acid_kewpie 04-25-2005 12:49 PM

not sure if you're going from a programming angle with the references to poll() there, but i'd suggest you look toward udev rules, assuming you're using udev of course. in a specific rule you can set a PROGRAM= variable to run a script on a device being connected. not sure about disconnection, as i've never done it, but i expect it's simple.

lordofring 04-25-2005 01:15 PM

Your guess is correct. My question is about programming. My application needs to monitor usb devices plugged in/out. And I don't think I can use udev since my kernel is 2.4.28. Thanks anyway.


All times are GMT -5. The time now is 09:45 AM.