LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-31-2011, 11:58 PM   #1
technogothica
LQ Newbie
 
Registered: May 2011
Posts: 3

Rep: Reputation: Disabled
Device change notification on Linux


Hi all,

On Windows, whenever you plug in or unplug a device such as USB external hard disk or game controller, the application is sent a WM_DEVICECHANGE message.

What is the equivalent approach to detecting device changes on Linux?

I don't need specific details of what changes has occurred, all I want is some notification that something has been plugged in or unplugged.

Thanks in advance.
 
Old 06-01-2011, 02:42 AM   #2
xylex_blaiste
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
Quote:
Originally Posted by technogothica View Post
Hi all,

On Windows, whenever you plug in or unplug a device such as USB external hard disk or game controller, the application is sent a WM_DEVICECHANGE message.

What is the equivalent approach to detecting device changes on Linux?

I don't need specific details of what changes has occurred, all I want is some notification that something has been plugged in or unplugged.

Thanks in advance.
Try this one http://udev-notify.learnfree.eu/. It should run on most Linux distros provided udev is used/installed. Hope that helps.
 
Old 06-01-2011, 03:04 AM   #3
technogothica
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by xylex_blaiste View Post
Try this one http://udev-notify.learnfree.eu/. It should run on most Linux distros provided udev is used/installed. Hope that helps.
Thanks for the link. I'm actually looking for an API based approach for a C/C++ application, so udev-notify is not quite what I'm after.

However, I notice that udev-notify uses udev to monitor device changes, and I also see that there is a libudev library which looks promising.

Is libudev the best (i.e. most efficient and most widely supported) way to check for device changes?
 
Old 06-01-2011, 04:34 AM   #4
xylex_blaiste
LQ Newbie
 
Registered: Jan 2007
Posts: 7

Rep: Reputation: 0
I linked udev-notify because it might help you start from somewhere. I was aware your question was programming related but wasn't really sure, hence I dropped that link and know you'd pick it up from where it might lead you (to where its getting its info, from udev). Yes and it's (udev-notify) python, but it (udev) can be for any capable language.

Quote:
Originally Posted by wiki
udev is the device manager for the Linux kernel. Primarily, it manages device nodes in /dev. It is the successor of devfs and hotplug, which means that it handles the /dev directory and all user space actions when adding/removing devices, including firmware load.
I'd say it's the best place to start because it is common for all distros using 2.6.x kernels.
 
Old 06-01-2011, 07:24 AM   #5
technogothica
LQ Newbie
 
Registered: May 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by xylex_blaiste View Post
I linked udev-notify because it might help you start from somewhere. I was aware your question was programming related but wasn't really sure, hence I dropped that link and know you'd pick it up from where it might lead you (to where its getting its info, from udev). Yes and it's (udev-notify) python, but it (udev) can be for any capable language.
No worries, you put me on the right track. Very much appreciated

Quote:
I'd say it's the best place to start because it is common for all distros using 2.6.x kernels.
If it's guaranteed to work on all current versions of Linux, then it will do the trick! I'm going to give libudev a try tonight. Thanks again!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
file change notification usman.mughall Linux - Security 10 01-19-2010 06:47 PM
Change notification defaults... custangro LQ Suggestions & Feedback 2 05-23-2007 01:44 PM
Email change notification in SendMail. thekillerbean Linux - Software 0 10-12-2005 02:23 PM
resolution change notification event?? pndhana Linux - General 2 09-22-2002 05:18 PM
event notification for resolution change?? pndhana Linux - Hardware 2 09-22-2002 04:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration