简体   繁体   English

Linux内核开发

[英]Linux kernel development

I want to run some script/binary after system start and every 1000 ms (for example) inside Linux kernel (without the use of software as a crontab and kernel modules). 我想在系统启动后以及在Linux内核中每1000毫秒(例如)运行一些脚本/二进制文件(例如,不使用软件作为crontab和内核模块)。 Where can I put such code: 我在哪里可以放这样的代码:

#include <linux/kmod.h>

char *envp[] = { "HOME=/", NULL };
char *argv[] = { "/bin/ls", NULL };

call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC);

Try to use kernel timer API: 尝试使用内核计时器API:

https://www.ibm.com/developerworks/library/l-timers-list/ https://www.ibm.com/developerworks/library/l-timers-list/

The simplest method is a call to setup_timer, which initializes the timer and sets the user-provided callback function and context. 最简单的方法是对setup_timer的调用,该调用将初始化计时器并设置用户提供的回调函数和上下文。 Otherwise, the user can set these values (function and data) in the timer and simply call init_timer. 否则,用户可以在计时器中设置这些值(函数和数据),只需调用init_timer。 Note that init_timer is called internally by setup_timer" 请注意,setup_timer在内部调用了init_timer”

 void init_timer( struct timer_list *timer ); void setup_timer( struct timer_list *timer, void (*function)(unsigned long), unsigned long data ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM