linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* defunc thread?
@ 2003-07-15 13:54 mingz
  0 siblings, 0 replies; only message in thread
From: mingz @ 2003-07-15 13:54 UTC (permalink / raw)
  To: linux-kernel

I code a smal example about kernel thread. But when I 
insmod thrtest.o &
more /proc/testthread
ps aux

then i can see my thread become defunc. if i 
insmod (and wait till it return, )
more /proc/testthread, 
ps aux, 

the thread status is correct. can anybody tell me why? thx

ming
---------------------------------------------------------------------------------
#include <linux/errno.h>    /* Miscellaneous error codes */
#include <linux/stddef.h>   /* NULL */
#include <linux/slab.h>     /* kmalloc() */
#include <linux/module.h>   /* EXPORT_SYMBOL */
#include <linux/pci.h>
#include <linux/smp_lock.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/interrupt.h>

DECLARE_WAIT_QUEUE_HEAD(test_wait);

int t_thread(void *startup)
{
	int i = 0;
	
	lock_kernel();
	daemonize();
	current->tty = NULL;
	strcpy(current->comm, "testthread");
	unlock_kernel();

	spin_lock_irq(&current->sigmask_lock);
	sigfillset(&current->blocked);
	recalc_sigpending(current);
	spin_unlock_irq(&current->sigmask_lock);

	complete((struct completion *)startup);

	printk("test thread up and call complete\n");
	interruptible_sleep_on(&test_wait);
	printk("thread wake up %d times\n", ++i);

	printk("test thread do cleanup work\n");

	return 0;
}

int test_read_procmem(char *buf, char **start, off_t offset, int count, int 
*eof, void *data)
{
        int len = 0;

        len += sprintf(buf+len,"test v0.1 Dragonfly, ELE, URI\n");
        *eof = 1;

	wake_up_interruptible(&test_wait);
        return len;
}

static struct completion startup = COMPLETION_INITIALIZER(startup);

int test_init(void)
{
	kernel_thread(t_thread, &startup, CLONE_FS | CLONE_FILES | CLONE_SIGNAL);
	wait_for_completion(&startup);

	create_proc_read_entry("testthread", 0, NULL, test_read_procmem, NULL);
	
	set_current_state (TASK_INTERRUPTIBLE);
	schedule_timeout (30*HZ);
	__set_current_state (TASK_RUNNING);

	return 0;
}

void test_clean(void)
{
	remove_proc_entry("helpm", NULL);
}

module_init(test_init);
module_exit(test_clean);

MODULE_DESCRIPTION("Test Thread");
MODULE_LICENSE("GPL");




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-15 14:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-15 13:54 defunc thread? mingz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).