Fixturessd Fixturessd - 1 year ago 97
Linux Question

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). 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);

Thanks all!

Answer Source

Try to use kernel timer API:

The simplest method is a call to setup_timer, which initializes the timer and sets the user-provided callback function and context. Otherwise, the user can set these values (function and data) in the timer and simply call init_timer. Note that init_timer is called internally by setup_timer"

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