* how to find a task through name faster? [not found] <CANudz+sqkachOT7r9=-rc98nCEO_QOCx7KiBi5=NWaj5exmEPA@mail.gmail.com> @ 2011-07-11 16:52 ` loody 2011-07-11 17:51 ` Chris Friesen 2011-07-11 20:16 ` Jiri Slaby 0 siblings, 2 replies; 9+ messages in thread From: loody @ 2011-07-11 16:52 UTC (permalink / raw) To: linux-kernel 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? -- Regards, -- Regards, ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 16:52 ` how to find a task through name faster? loody @ 2011-07-11 17:51 ` Chris Friesen 2011-07-11 17:57 ` loody 2011-07-11 20:16 ` Jiri Slaby 1 sibling, 1 reply; 9+ messages in thread From: Chris Friesen @ 2011-07-11 17:51 UTC (permalink / raw) To: loody; +Cc: linux-kernel 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 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 17:51 ` Chris Friesen @ 2011-07-11 17:57 ` loody 2011-07-11 18:23 ` Muthu Kumar 2011-07-11 19:55 ` Chris Friesen 0 siblings, 2 replies; 9+ messages in thread From: loody @ 2011-07-11 17:57 UTC (permalink / raw) To: Chris Friesen; +Cc: linux-kernel hi: 2011/7/12 Chris Friesen <chris.friesen@genband.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? Thanks for your reply > 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. actually, I only have the name for searching, since the thread start and finish periodically, pid of it will change dynamically. If I save the pid, next time it will change and be no use to me > > 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 -- Regards, ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 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 1 sibling, 1 reply; 9+ messages in thread From: Muthu Kumar @ 2011-07-11 18:23 UTC (permalink / raw) To: loody; +Cc: Chris Friesen, linux-kernel Let me ask a trivial question: Should this be done in kernel? Can't you push it to user space and walk the /proc to find if the process is there. On Mon, Jul 11, 2011 at 10:57 AM, loody <miloody@gmail.com> wrote: > hi: > > 2011/7/12 Chris Friesen <chris.friesen@genband.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? > > Thanks for your reply > >> 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. > > actually, I only have the name for searching, since the thread start > and finish periodically, pid of it will change dynamically. If I save > the pid, next time it will change and be no use to me >> >> 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 > > > -- > Regards, > -- > 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/ > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 18:23 ` Muthu Kumar @ 2011-07-11 19:39 ` loody 0 siblings, 0 replies; 9+ messages in thread From: loody @ 2011-07-11 19:39 UTC (permalink / raw) To: Muthu Kumar; +Cc: Chris Friesen, linux-kernel hi: 2011/7/12 Muthu Kumar <muthu.lkml@gmail.com>: > Let me ask a trivial question: Should this be done in kernel? Can't > you push it to user space and walk the /proc to find if the process is > there. The root file system is fixed, that means I cannot add any program as I want. BTW, will that be faster is run a user mode program to walk through /proc? it still need to search one by one, right? Thanks for your reply. BR, ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 17:57 ` loody 2011-07-11 18:23 ` Muthu Kumar @ 2011-07-11 19:55 ` Chris Friesen 1 sibling, 0 replies; 9+ messages in thread From: Chris Friesen @ 2011-07-11 19:55 UTC (permalink / raw) To: loody; +Cc: linux-kernel On 07/11/2011 11:57 AM, loody wrote: > 2011/7/12 Chris Friesen<chris.friesen@genband.com>: >> 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. > > actually, I only have the name for searching, since the thread start > and finish periodically, pid of it will change dynamically. If I save > the pid, next time it will change and be no use to me If this is critical to your system performance you could customize the kernel to do some sort of indexing based on the name. This would involve a bit more work on task startup/shutdown and when the name is changed, but it would make it faster to search for a task by name. Chris -- Chris Friesen Software Developer GENBAND chris.friesen@genband.com www.genband.com ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 16:52 ` how to find a task through name faster? loody 2011-07-11 17:51 ` Chris Friesen @ 2011-07-11 20:16 ` Jiri Slaby 2011-07-13 7:55 ` loody 1 sibling, 1 reply; 9+ messages in thread From: Jiri Slaby @ 2011-07-11 20:16 UTC (permalink / raw) To: loody; +Cc: linux-kernel On 07/11/2011 06:52 PM, 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? It depends on what you are trying to achieve. Maybe process accounting is what you want? -- js ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-11 20:16 ` Jiri Slaby @ 2011-07-13 7:55 ` loody 2011-07-13 9:21 ` Jiri Slaby 0 siblings, 1 reply; 9+ messages in thread From: loody @ 2011-07-13 7:55 UTC (permalink / raw) To: Jiri Slaby; +Cc: linux-kernel hi: 2011/7/12 Jiri Slaby <jirislaby@gmail.com>: > On 07/11/2011 06:52 PM, 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? > > It depends on what you are trying to achieve. Maybe process accounting > is what you want? Would you mind to explain what is "process accounting"? I ask this question cause I need to do something in my kernel driver when a thread starting running. is there any rule to assign a pid before starting a thread? if there is a rule or range, such 100 ~200 for A type, 200~300 for B type, I can focus on specific type of thread in that range instead of searching everyone. -- Regards, ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: how to find a task through name faster? 2011-07-13 7:55 ` loody @ 2011-07-13 9:21 ` Jiri Slaby 0 siblings, 0 replies; 9+ messages in thread From: Jiri Slaby @ 2011-07-13 9:21 UTC (permalink / raw) To: loody; +Cc: linux-kernel On 07/13/2011 09:55 AM, loody wrote: > hi: > > 2011/7/12 Jiri Slaby <jirislaby@gmail.com>: >> On 07/11/2011 06:52 PM, 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? >> >> It depends on what you are trying to achieve. Maybe process accounting >> is what you want? > Would you mind to explain what is "process accounting"? http://lmgtfy.com/?q=process+accounting+linux > I ask this question cause I need to do something in my kernel driver > when a thread starting running. No, it doesn't work that way. You have to explain what exactly you want to do (i.e. show sources and describe) so that people can actually help you. regards, -- js ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-07-13 9:21 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [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 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
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.