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 08-09-2018, 09:50 AM   #1
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Rep: Reputation: 17
Tracking hotplug devices


I need to programatically track the addition or deletion of hotplug block devices. I can either track this as some sort of notification when a new hotplug device ( thumb drive in my specific case ) is added to the device system in Linux, or I can enumerate the block devices at different point in the program and compare them. How would I do this in either case ? Is scanning the /dev directory a reliable means of knowing which devices are available in modern Linux systems or is there a better way ?
 
Old 08-09-2018, 11:34 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
I would google for /proc/sys/kernel/hotplug
 
Old 08-09-2018, 02:04 PM   #3
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
You could monitor for udev events...
Code:
udevadm monitor
 
Old 08-10-2018, 04:30 AM   #4
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by ferrari View Post
You could monitor for udev events...
Code:
udevadm monitor
I should have been more specific and mentioned that I am looking for a solution for a C/C++ program and not for an OS shell script.
 
Old 08-10-2018, 04:34 AM   #5
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by NevemTeve View Post
I would google for /proc/sys/kernel/hotplug
Thanks ! By programming I meant for use in C/C++ code.
 
1 members found this post helpful.
Old 08-10-2018, 06:28 AM   #6
eldiener
Member
 
Registered: Nov 2006
Distribution: Mepis, CentOS, OpenSuse
Posts: 106

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by eldiener View Post
I need to programatically track the addition or deletion of hotplug block devices. I can either track this as some sort of notification when a new hotplug device ( thumb drive in my specific case ) is added to the device system in Linux, or I can enumerate the block devices at different point in the program and compare them. How would I do this in either case ? Is scanning the /dev directory a reliable means of knowing which devices are available in modern Linux systems or is there a better way ?
It looks like libudev is the answer, with the best documentation at http://presbrey.scripts.mit.edu/doc/libudev/. If there is any third party libraries built on top of libudev I would of course be happy to hear about them.
 
Old 08-10-2018, 09:56 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Most certainly, the handler-program you pass to the kernel via /proc/sys/kernel/hotplug is supposed to be written in C.
 
  


Reply

Tags
hotplug, tracking



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
Hotplug of PCIe switch devices. nskogler Linux - Hardware 3 03-24-2015 08:10 PM
flush vs sync for fstab vfat hotplug devices jrfk2 Linux - Hardware 0 11-16-2007 06:35 AM
Multiple USB devices with hotplug support vdemuth Slackware 2 12-06-2004 04:58 PM
usb devices not seen despite hotplug Emmanuel_uk Linux - Newbie 2 11-18-2004 01:36 AM
Can Hotplug detect USB devices in a certain order? SAM_site Linux - General 0 07-10-2004 07:27 AM

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

All times are GMT -5. The time now is 03:19 AM.

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