Re: Clean kernel thread termination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 01 Jun 2005 17:20:49 +0200
Thomas Petazzoni <thomas.petazzoni@xxxxxxxx> wrote:

> I would like to know how to cleanly terminate a kernel thread at
> module removal.

Just for the archives, because I guess my solution won't fit your needs
if you use kernel 2.4.

Using kernel 2.6, there is a quite simple API available for that:

static struct task_struct *my_thread = NULL;

static int thread_task(void *arg)
{
	while(!kthread_should_stop()) {
		...
		msleep_interruptible(2000);
	}
}

static int __init my_module_init() {
        my_thread = kthread_run(thread_task, th, "kmyname");
	if (my_thread == ERR_PTR(-ENOMEM)) {
		...
		my_thread = NULL;
	}
}

static int __init my_module_exit() {
	if (my_thread != NULL)
		kthread_stop(my_thread);
}

-- 
Colin

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux