lkml.org 
[lkml]   [2011]   [Jul]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: how to find a task through name faster?
On 07/11/2011 10:52 AM, loody wrote:
> hi all:
> I found a way to find a task I need by name, test, as below:
> for_each_process(task) {
> if(strcmp(task->comm, "test")
> 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?

The names of tasks isn't indexed in any way so the above is about as
good as it gets if that's all the information you have.

One common way around that is to store the PID in a file somewhere at
startup. Then you can look in the file and see if that PID is present
and check "task->comm" to make sure it's what you expect. This saves
having to search through all tasks.

Chris

--
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2011-07-11 19:55    [W:1.521 / U:0.032 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site