Re: Trying to make kernel thread sleep

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

 



Hi Mulyadi,

Sorry for being late in replying back. I have used
schedule_timeout and it is working fine. But curious
to know what wrong is going on while using wait
queues.
I am working on kernel 2.4.20
Here is full code:


static DECLARE_WAIT_QUEUE_HEAD(wait_kernelthread);

static int print_taskinfo(void * data)
{
	printk("<1>::Inside Thread Function::\n");
        printk("Kernel Thread::Current Process is \"%s
\" (pid: %i) \n", current->comm,current->pid);
	sprintf(current->comm,"MyTask" );
	set_current_state(TASK_INTERRUPTIBLE);

        void * sZombie = kmalloc(10 * sizeof(char),
GFP_KERNEL);
        memset(sZombie,'\0', 10 * sizeof(char));
                                                      
                              
        // Not very clear who will clean up a
temporary memory allocated for
        // string literals "ZOMBIE" & "NON-ZOMBIE"...
        memcpy(sZombie, "ZOMBIE", 7);
   
        void * sNonZombie = kmalloc(15 * sizeof(char),
GFP_KERNEL);
        memset(sNonZombie,'\0', 15 * sizeof(char));
        memcpy(sNonZombie, "NON-ZOMBIE", 12);
       	
	struct task_struct *p ;
        printk("<1>Starting Iteration\n");
        for_each_process(p) {
       	      // Iterating each element of task list.
              printk ("Task List::Process PID =
%i,::PPID = %i,::State = %ld
::Zombie=%s\n",p->pid,p->parent->pid,p->state,
(p->state == TASK_ZOMBIE)? (char*)sZombie :
(char*)sNonZombie);
	}

  
interruptible_sleep_on_timeout(&wait_kernelthread,HZ);
	// Release memory allocated via kmalloc.
        kfree(sZombie);
        kfree(sNonZombie);
	printk("<1> Exiting Thread Function::");	
}

int init_module(void)	
{
	printk("<1>Hello Kernel World! Kernel 2.4.20\n");
  	printk("The current Process is \"%s \" (pid: %i)
\n", current->comm,current->pid);	
	kernel_thread((int (*)(void *))print_taskinfo,NULL,
CLONE_KERNEL|SIGCHLD);
	return 0;
}




--- Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx> wrote:

> Hi Dinesh...
> 
> > static int print_taskinfo(void * data)
> > {
> >      wait_queue_head_t wait;
> >
> >
> > init_waitqueue_head (&wait);
> >      for (;;)
> >      {
> >          // do something useful here.
> >          interruptible_sleep_on_timeout(&wait,
> HZ);
> >          //check whether we have to break loop or
> > continue.
> >      }
> 
> Just a wild guess (because you don't show us your
> whole codes): task is 
> woken up, but "wait" is already destroyed?
> 
> And...do you really need sleep_on? If you just need
> delay, why not using 
> schedule_timeout() ?
> 
> Please paste the whole code as many as possible so
> we can analyze it 
> better
> 
> regards,
> 
> Mulyadi
> 



		
__________________________________________________________
Yahoo! India Answers: Share what you know. Learn something new
http://in.answers.yahoo.com/

--
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