accessing the struct task_struct using a pid

From: Amit Nadgar (
Date: Sat Jun 15 2002 - 16:06:20 EST

   I am writing a kernel module where I am trying to
access the task_structs. Now I have tried this using
various mathods.
   1) Using the pidhash array.
      Here when I do a insmod I get a unresolved
   2) Directly accessing the location of pidhash as
seen in
      Here when the pidhash_fn hashes the supplied pid
the particular location into which it indexes in NULL.
  3) Starting from the init_task.
     here the next task after the init task is found
to be NULL.

Could some one help me in this matter.

Following is the piece of code which executes when an
apploication program does a sys_ptrace.

int new_syscall(long request,long pid,long addr,long
  struct task_struct *my_init_task = (struct
task_struct *)&init_task;
  struct task_struct *task_ptr;
        task_ptr = my_init_task;
        while(task_ptr && (task_ptr->next_task !=
                  printk("<1> task_ptr pointer is %x\n",task_ptr);
                  printk("<1> task_ptr->pid is %d\n",task_ptr->pid);
                printk("<1> task_ptr->next_task is
                task_ptr = (struct task_struct*)task_ptr->next_task;
        printk("<1> my_init_task pointer is
        return 0;
/* ((long int (*)

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sat Jun 15 2002 - 22:00:33 EST