All of lore.kernel.org
 help / color / mirror / Atom feed
* faster way to find task
@ 2011-07-11 16:16 loody
  2011-07-11 16:34 ` loody
  0 siblings, 1 reply; 4+ messages in thread
From: loody @ 2011-07-11 16:16 UTC (permalink / raw)
  To: kernelnewbies

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,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110712/53951236/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* faster way to find task
  2011-07-11 16:16 faster way to find task loody
@ 2011-07-11 16:34 ` loody
  2011-07-11 17:01   ` Nuno Martins
  0 siblings, 1 reply; 4+ messages in thread
From: loody @ 2011-07-11 16:34 UTC (permalink / raw)
  To: kernelnewbies

Hi all:

2011/7/12 loody <miloody@gmail.com>

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


-- 
Regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110712/65ddaee1/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* faster way to find task
  2011-07-11 16:34 ` loody
@ 2011-07-11 17:01   ` Nuno Martins
  2011-07-11 17:13     ` loody
  0 siblings, 1 reply; 4+ messages in thread
From: Nuno Martins @ 2011-07-11 17:01 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Jul 11, 2011 at 5:34 PM, loody <miloody@gmail.com> wrote:

> Hi all:
>
>
> 2011/7/12 loody <miloody@gmail.com>
>
>> 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?
>
>
>
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.
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<http://lxr.linux.no/linux+v2.6.39/+code=task_struct>*
find_task_by_vpid<http://lxr.linux.no/linux+v2.6.39/+code=find_task_by_vpid>
(pid_t <http://lxr.linux.no/linux+v2.6.39/+code=pid_t>
vnr<http://lxr.linux.no/linux+v2.6.39/+code=vnr>
);

Have a good work.


> --
> Regards,
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


-- 
Nuno Martins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110711/90e5f3ce/attachment.html 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* faster way to find task
  2011-07-11 17:01   ` Nuno Martins
@ 2011-07-11 17:13     ` loody
  0 siblings, 0 replies; 4+ messages in thread
From: loody @ 2011-07-11 17:13 UTC (permalink / raw)
  To: kernelnewbies

hi:


2011/7/12 Nuno Martins <nuno.m.g.martins@gmail.com>:
>
>
> On Mon, Jul 11, 2011 at 5:34 PM, loody <miloody@gmail.com> wrote:
>>
>> Hi all:
>>
>> 2011/7/12 loody <miloody@gmail.com>
>>>
>>> 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,

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-07-11 17:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11 16:16 faster way to find task loody
2011-07-11 16:34 ` loody
2011-07-11 17:01   ` Nuno Martins
2011-07-11 17:13     ` loody

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.