Ubuntu Linux - 插入 USB 设备时生成应用程序
我试图让一个应用程序在插入 USB 设备时运行:闪存驱动器、相机、电话等。我可能会从一个简单的应用程序(如“Hello World”)开始。所以基本上,当我插入相机、闪存驱动器或手机时,我希望我的计算机生成一个“Hello World”应用程序。
是否可以在最新版本的 Ubuntu Linux 上创建此类功能?我需要创建一个应用程序来侦听此事件吗?我宁愿做的就是让它工作,而不需要运行应用程序来捕获它。这可能吗?
我需要写的任何东西都将用 C 语言编写。如果有人能指出我正确的方向,我将非常感激。
谢谢, 时间
I'm trying to get an application to run whenever a USB device is plugged in: Flash drive, Camera, phone, etc. I'll probably start with a simple application like "Hello World". So basically, when I plug in a camera, flash drive, or phone I want my computer to spawn a "Hello World" application.
Is it possible to create this sort of functionality on the latest version of Ubuntu Linux? Would I need to create an application to listen for this event? What I would rather do is just have it work without having an to have an application running to catch it. Is this possible?
Anything I need to write will be in C. If someone could point me in the right direction, I would be very grateful.
Thanks,
T
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要的是 udev 规则——udev 是一个守护进程,它等待内核事件(如硬件安装)并处理您定义的一组“规则”。这里有一个不错的教程,最后有几个符合您要求的示例。
What you want is a udev rule -- udev is a daemon that waits for kernel events (like hardware mounts) and processes a set of "rules" that you define. There's a nice tutorial here which has several examples at the end that match your request.
您应该查看 UDEV: http://www.kernel.org /pub/linux/utils/kernel/hotplug/udev.html
最重要的是,我建议查看 hal: http://www.freedesktop.org/wiki/Software/hal 虽然它开始变老了
最后udisks:http://www.freedesktop.org/wiki/Software/udisks
You should look into UDEV: http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html
On top of that I would suggest looking into hal: http://www.freedesktop.org/wiki/Software/hal Though it is starting to get old
Finally udisks: http://www.freedesktop.org/wiki/Software/udisks