[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: daemon
On 4/5/07, Erik Mouw <mouw@xxxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Apr 05, 2007 at 09:05:43AM +0100, Hemanth Kumar wrote:
> I need some help in writing daemon , I googled it but
> unable to find any good links , can some body please
> give me good links on writing daemons .
How is this kernel related?
I see daemons in the kernel too!
Cifs/jffs /usb-storage/sas-queue many others
Various places people are doing
Kernel_therad()
And then in the thread routine
Daemonize()
May be unblock some signals
allow_signal(SIGKILL);
allow_signal(SIGSTOP);
allow_signal(SIGCONT);
& loop/do ur work.. until you are interrupted
Here daemonize works similar to what is said for userspace
It creates a thread with no userspace resources attached
Blocks signals
Does reparent_to_init()
Some example code below.
You can see it in ps listing
And then Kill it
---
int daemon_routine(void * data)
{
printk(KERN_INFO "Inside daemon_routine() \n");
daemonize("kern_daemon");
allow_signal(SIGKILL);
allow_signal(SIGTERM);
do{
printk(KERN_INFO "kerne_daemon alive\n");
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(10*HZ);
}while(!signal_pending(current));
return 0;
}
int kerndaemon_init(void)
{
int ret_val=0;
printk(KERN_INFO"kernel daemon starting a kernel thread\n");
ret_val = kernel_thread(daemon_routine,NULL,0);
if(ret_val < 0 ){
printk(KERN_ALERT "Daemon thread creation failed\n");
return -1;
}
printk(KERN_INFO"kernel daemon \n");
return 0;
}
--
Milind Arun Choudhary
--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ