just try out this, insert this in your init module and then compile the code

 /* Set up the anchor point */
  struct task_struct *task = &init_task;

  /* Walk through the task list, until we hit the init_task again */
  do {

        //printk(KERN_ALERT "Process has started....................");
        /*printk( KERN_INFO "*** %s [%d] parent %s\n",task->comm, task->pid,
task->parent->comm );*/
        ptr = task->comm;
        trace_gedit = string;
        while( *ptr != '\0' && *ptr == *trace_gedit)
        {
           ptr++;trace_gedit++;
        }
        if(*ptr == '\0' && *trace_gedit == '\0')
        {
             flag = 1;
             printk(KERN_INFO "\n*** %s [%d] process has tracked
\n",task->comm,task->pid);
             break;
        }
   flag = 0;
  } while ( (task = next_task(task)) != &init_task );

  if( flag == 0 )
  {
       printk(KERN_INFO "\n***Not able to trace gedit process");
  }



On Tue, Mar 23, 2010 at 8:05 AM, perumal316 <[email protected]> wrote:

> Hi,
>
> Thanks for the help. Yah when I use current->pid and current->comm in
> the module, I am getting the process ID and name. I think i am having
> problem because I tried the module on Android and in there the process
> name is given as Binder Thread and not the application's name. I will
> post this question in Android forum to find out more.
>
> Thanks and Regards,
> Perumal
>
> On Mar 22, 4:19 pm, Peter Teoh <[email protected]> wrote:
> > not sure how u wrote your module.....want to post your code here?
> >
> > From kernel/timer.c:
> >
> >  373 void __timer_stats_timer_set_start_info(struct timer_list *timer,
> > void *addr)
> >  374 {
> >  375         if (timer->start_site)
> >  376                 return;
> >  377
> >  378         timer->start_site = addr;
> >  379         memcpy(timer->start_comm, current->comm, TASK_COMM_LEN);
> >  380         timer->start_pid = current->pid;
> >  381 }
> >
> > the answer is obvious......i suspect u got your global variable
> > "current" wrongly.
> >
> > look into:
> >
> > ./arch/x86/kernel/cpu/common.c:
> > EXPORT_PER_CPU_SYMBOL(current_task);
> >
> > u can see that "current_task" is per-CPU and is exported, ie,
> > different CPU may be executing different task.
> >
> > so, from ./Documentation/uml/UserModeLinux-HOWTO.txt:
> >        (gdb) p current_task.pid
> >        (gdb) p current_task.prev_task.comm
> >        (gdb) p current_task.prev_task.thread
> >
> > Or inside your kernel module....just do current_task->comm will do, as
> > the symbol is exported.
> >
> > But I cannot find EXPORT declaration for "current", so your kernel
> > module cannot access the global variable directly - roundabout way
> > needed.
> >
> > But if you compile your codes + kernel together, NOT USING KERNEL
> > MODULE, then access any global variable (eg, current) is possible.
> >
> > On Mar 22, 10:42 am, perumal316 <[email protected]> wrote:
> >
> > > Hi,
> >
> > > Is there any way to get the current process ID and the corresponding
> > > name of the application from the kernel module?
> >
> > > I have tried using task->comm ,task->pid, current->pid etc But I am
> > > not getting the correct process ID.
> >
> > > I want to printk the process ID and the application name each time a
> > > system call is called. System call should have a way to identify which
> > > process ID or application is calling it.
> >
> > > Any other way to printk the process ID and the application name?
> >
> > > Thanks In Advance,
> > > Perumal
>
> To unsubscribe from this group, send email to linuxkernelnewbies+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>


-- 
To unsubscribe, reply using "remove me" as the subject.

Reply via email to