TASK_STOPPED state ??

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

 



hi all,
            i tried the following code on linux-2.4-18 kernel relaease.I had posted this question before,but coudnt get
a reply, which was satisfactory,and help understand the problem.In the code below i try setting a task_struct's state
field to TASK_STOPPED and expected it to stop. It didnt. So i called schedule() after i do temp1->state =
TASK_STOPPED,but even then it didnt stop.
where, temp1 points to the task_struct of the task which has to be stopped.

When i insmod the module it returns to the command prompt with no errors.
I get the following output:
/root]#insmod ./test_mod.o

Found tester 1...temp->state = 0    // that indicates it was in TASK_RUNNING state 
Found tester 1...temp->state = 8    // that says it has moved to TASK_STOPPED state.
After Schedule temp1->state  = 8    // it is still in TASK_STOPPED state.

/root]#

And tester.c is a small peice of code with :

main() 
{
  int counter=0;
  while(1) 
   {   
      
      printf( "counter = %d",counter++); 
   }
}

so that it keeps running....
and i try to stop it.
Could someone explain ???

cheers,
Amith

Code follows ....



#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/version.h>
#include<linux/sched.h>
#include<linux/string.h>

#if 0
 #if defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS)
   #include <linux/modversions.h> 
   #define MODVERSIONS
#endif         


#endif

MODULE_LICENSE("GPL");  
volatile struct task_struct  *temp;

void xxxxx()
{
  struct task_struct *temp1;
    
  temp = get_current();	 
  // 1) i get a pointer to a task_struct, but which list am i traversing ?

  temp1=temp->next_task;
  for(; temp!=temp1; temp1=temp1->next_task )   {
	  if(strcmp(temp1->comm,"tester")==0) {
            printk("<1>Found tester 1...temp->state = %d \n",temp1->state);
	    temp1->state = TASK_STOPPED;
            printk("<1>Found tester 2...temp->state = %d \n",temp1->state);
	    schedule();
	    printk("<1>After Schedule temp1->state = %d\n",temp1->state);
	    return;
        }	  
     printk("<1> Current->comm = %s\n",temp1->comm);
  }
}


int
init_module(void)
{         
        xxxxx();
	printk("<1> returned from xxxxx() \n");
	return 0;

}

void
cleanup_module(void)
{
}

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