defunc thread?

From: mingz (mingz@ele.uri.edu)
Date: Tue Jul 15 2003 - 08:54:42 EST


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

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Jul 15 2003 - 22:00:57 EST