From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965166Ab1GMJVJ (ORCPT ); Wed, 13 Jul 2011 05:21:09 -0400 Received: from mail-fx0-f52.google.com ([209.85.161.52]:35156 "EHLO mail-fx0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965108Ab1GMJVH (ORCPT ); Wed, 13 Jul 2011 05:21:07 -0400 Message-ID: <4E1D637D.1050004@gmail.com> Date: Wed, 13 Jul 2011 11:21:01 +0200 From: Jiri Slaby User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: loody CC: linux-kernel@vger.kernel.org Subject: Re: how to find a task through name faster? References: <4E1B5A1E.4060604@gmail.com> In-Reply-To: X-Enigmail-Version: 1.2pre Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/13/2011 09:55 AM, loody wrote: > hi: > > 2011/7/12 Jiri Slaby : >> 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