I am writing a kernel module which acts as a memory storage. And I want to backup the data every 10 seconds to a file. I think kernel timer can solve this, but I think it is too troublesome to be used and seems it can’t run probably with kthread. Any better method to perform a function repeatedly in a set time interval apart from using kernel timer. Please suggest me some better method. any if possible tell me more about how that can be implemented or give me some reference about its usage.
Thank you
I am writing a kernel module which acts as a memory storage. And I
Share
You could look at
schedule_delayed_work()in<linux/workqueue.h>. That runs your work item in process context after a delay you specify. You’ll need your work function to reschedule itself to run again (ie callschedule_delayed_work()again on itself), but this is a pretty standard thing to do.If you really want to have your own kernel thread, you could use
schedule_timeout()to delay yourself for 10 seconds. Or go to sleep and use a timer to wake yourself up (I agree with the other answer — the timer API is pretty easy to use).