When ever i press the button it need to run a shell command

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

When ever i press the button it need to run a shell command

跳至解决方案
1,686 次查看
aravinthkumarja
Senior Contributor II

Hi All,

I'm using iMX6 sabresd board and Android 6 platform. Any one of gpio i configured as button.

When ever the user press the button, i need to run a shell command(or shell script) on board.

How can i do this .?

Regards,

Aravinth

标签 (4)
0 项奖励
回复
1 解答
1,353 次查看
aravinthkumarja
Senior Contributor II

Thanks for your response Carlos. I have used call_usermodehelper function to call shell command in kernel.

Regards,

Aravinth

在原帖中查看解决方案

0 项奖励
回复
6 回复数
1,352 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi,

in the following link you will find the code for a .ko module which handles a GPIO interrupt and the device tree configuration required for this.

Issue with configuring GPIO as an interrupt - i.MX6Q 

For the shell command you can just use a system call E.g. sytem("command");


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
1,352 次查看
aravinthkumarja
Senior Contributor II

Hi Carlos,

Thanks for your response.  For system function what library i have to use in imx6 kernel.?

Regards,

Aravinth

0 项奖励
回复
1,353 次查看
Carlos_Musich
NXP Employee
NXP Employee

it is stdio.h, this is a general C question, you can find a lot of information if you Google "linux shell command in c program" or "linux c system function".

0 项奖励
回复
1,353 次查看
aravinthkumarja
Senior Contributor II

Hi carlos,

I have used system function in normal c application. But in kernel code we can't add stdio.h. So i'm not able to use system function in kernel.!

Regards,

Aravinth

0 项奖励
回复
1,353 次查看
Carlos_Musich
NXP Employee
NXP Employee

You can make an application that communicates with the kernel module. So the module will use copy_to_user function to tell the applications that a button was pressed and the application will execute the shell command.

0 项奖励
回复
1,354 次查看
aravinthkumarja
Senior Contributor II

Thanks for your response Carlos. I have used call_usermodehelper function to call shell command in kernel.

Regards,

Aravinth

0 项奖励
回复