From: Chris Friesen <chris.friesen@genband.com>
To: loody <miloody@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: how to find a task through name faster?
Date: Mon, 11 Jul 2011 11:51:18 -0600 [thread overview]
Message-ID: <4E1B3816.2030606@genband.com> (raw)
In-Reply-To: <CANudz+vxY_0NY2veJ9Wvr08x_z3e20m=g7ZL4bZDi=-vaOF7dQ@mail.gmail.com>
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
next prev parent reply other threads:[~2011-07-11 17:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CANudz+sqkachOT7r9=-rc98nCEO_QOCx7KiBi5=NWaj5exmEPA@mail.gmail.com>
2011-07-11 16:52 ` how to find a task through name faster? loody
2011-07-11 17:51 ` Chris Friesen [this message]
2011-07-11 17:57 ` loody
2011-07-11 18:23 ` Muthu Kumar
2011-07-11 19:39 ` loody
2011-07-11 19:55 ` Chris Friesen
2011-07-11 20:16 ` Jiri Slaby
2011-07-13 7:55 ` loody
2011-07-13 9:21 ` Jiri Slaby
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E1B3816.2030606@genband.com \
--to=chris.friesen@genband.com \
--cc=linux-kernel@vger.kernel.org \
--cc=miloody@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox