Re: faster way to find task

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

 



hi:


2011/7/12 Nuno Martins <nuno.m.g.martins@xxxxxxxxx>:
>
>
> On Mon, Jul 11, 2011 at 5:34 PM, loody <miloody@xxxxxxxxx> wrote:
>>
>> Hi all:
>>
>> 2011/7/12 loody <miloody@xxxxxxxxx>
>>>
>>> Dear all:
>>> Is there faster way to find a give name of task?
>>> for example, I have a thread, named "test", is there faster way to get
>>> the task struct  by passing "test" to some kernel api?
>>>
>>> --
>>> Regards,
>>
>> I found a way as below:
>> for_each_process(task) {
>> printk(“%s[%d]\n”, task->comm, task->pid);
>> }
>>
>> But it is time-consuming to do so if I periodically want to know whether
>> "test" exist or not.
>> is there better way to do so?
>>
Thanks for your help :)
> If you have the thread pid you could find it really fast. By name i don't
> know any function that could help you with that.

actually, I only have the name for searching, since the thread start
and finish periodically, pid of it will change dynamically. The only
thing that fixed is the name of the thread.

> You could search [1,2] for functions that could help you with that.
> If you are invoking from the thread you want, inside the kernel you can get
> the current variable that points to ther current process.
>
>  [1]  http://lxr.linux.no/linux+v2.6.39/kernel/pid.c#L426
>  [2] struct task_struct *find_task_by_vpid(pid_t vnr);
> Have a good work.
I will check what you mentioned above.
Thanks a lot,

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[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