Event button as a module or as user program?

2019-09-15 18:05发布

问题:

I am programming a push button to start the software in a linux based board. A push button on Linux based embedded board. GPIO didn't work with that Linux kernel, so instead, I used the event interface. The button is basically listening for button press to activate all the hardware and stops the hardware when it's pressed twice. I would like to know whether write as a kernel module or as a user program? Or as a deamon?

回答1:

If it's possible to do it in user space (i.e. daemon) you should do it there.

In this case both might be required. You'll need to access the button somehow, which will depend on what the hardware looks like. Then you'll need to respond to an event and perform an action based on that.

Following the 'policy does not belong in the kernel' mantra, this means that while you can (and probably need to) handle the button itself from the kernel you need to do the starting the application part from user space. The kernel should not be in the business of starting new user space processes. Instead it should pass the even to user space, through a netlink socket for example. You then need a user space daemon which listens on the netlink socket and starts the application in response to certain events.