Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,everyone.I am newbie in Linux programming.
Now i have a problem.in my program,i have to know the flash disk whether is being unplugged.but i don't know how to do.is there any system message can be captured? or any API to check system conditions?
any advices are appreciated!
dmesg (or /var/log/dmesg) will show output when devices are added or removed, but the output can be hard to process for specific changes.
I don't know if this is the best way, but the hal daemon monitors and reports all system hardware changes. "lshal --monitor" will show you what changes are made to the hal listings in real time as a device is added or removed, or even mounted and unmounted.
You can then use lshal with grep or something to test the state of the device in a script. Or alternately, you can use ivman, a daemon that lets you run commands on hal events. For example, you could have ivman create a text file when a device is added, and delete it when the device is removed. Then you can test for existence of that file.
I only know a little about scripting, so this is the extent of what I know, and there are probably better ways to do this in other programming languages. But hopefully this will give you some ideas.
HAL communicates with userland programs like KDE or Gnome via DBUS. You might want to study the python scripts that many systems have for examples on how to register with DBUS/HAL to receive event messages.
dmesg (or /var/log/dmesg) will show output when devices are added or removed, but the output can be hard to process for specific changes.
I don't know if this is the best way, but the hal daemon monitors and reports all system hardware changes. "lshal --monitor" will show you what changes are made to the hal listings in real time as a device is added or removed, or even mounted and unmounted.
You can then use lshal with grep or something to test the state of the device in a script. Or alternately, you can use ivman, a daemon that lets you run commands on hal events. For example, you could have ivman create a text file when a device is added, and delete it when the device is removed. Then you can test for existence of that file.
I only know a little about scripting, so this is the extent of what I know, and there are probably better ways to do this in other programming languages. But hopefully this will give you some ideas.
thank you very much!I have taken a try as your advice.some informations can be captured with the commands `dmesg`,`lshal` and so on when unplug event takes place.but the difficult is that i can't determine which device is what i need...
HAL communicates with userland programs like KDE or Gnome via DBUS. You might want to study the python scripts that many systems have for examples on how to register with DBUS/HAL to receive event messages.
thank you! I am studying the python scripts related with DBUS/HAL.
i used:
that will inform me when device removed.but the same problem is that i can't determine whether the device is what i need.maybe 'GetProperty(...) is useful.but i have no idea how to use it do you have any clue?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.