tags:

views:

60

answers:

1

Hi, I am learning some embedded programming. I am using Linux as my platform and I want to create a daemon program that will check if a particular device(magstrife, keypad, etc) is active. Like for example, my daemon program is running in the background, then when I make a keypress event, my deamon app will do something.

What implementation should I do to create this app? And how can I check the event of the devices?

Thanks.

+3  A: 

The most common way is to use poll(2). There is a text on how to implement it. You will need to implement open(2) as well.

unbeli
You mean, I have to poll each device if it is open or active?
sasayins
You open all devices you are interested in and then call poll(2). This will, basically, block, until there is anything interesting on any of them. Then you process that event and poll(2) again.
unbeli
I see thanks, is this a standard way to implement this kind of detecting?
sasayins
As far as I know, yes
unbeli
Thanks unbeli, but I think poll(2) is not preferred for what will I do. Because to use poll I need a open file descriptor a device, but other application will unable to use that open device since it is already open.
sasayins
This is up to your implementation of open(), you can allow multiple applications to open the device. There are very few ways to communicate between a program and a kernel driver without actually opening some file.
unbeli
What are the basic ways to communicate between a program and a kernel driver? Like accessing the sysfs attribute of a device?
sasayins
sysfs interface has no good way of event notification. It's designed for exposing attributes like configuration and status.
unbeli
i see. so accessing the sysfs attributes of a device is not advisable and poll(2) is the best implementation of this kind of senario. Now my problem is some of my devices returns quickly when I execute poll(2) even though I didn't make an event.
sasayins