From owner-freebsd-questions Thu Jul 26 13:57:41 2001 Delivered-To: freebsd-questions@freebsd.org Received: from p1.cs.ohiou.edu (p1.cs.ohiou.edu [132.235.1.11]) by hub.freebsd.org (Postfix) with ESMTP id E96BF37B406 for ; Thu, 26 Jul 2001 13:57:37 -0700 (PDT) (envelope-from frussell@p1.cs.ohiou.edu) Received: from localhost (frussell@localhost) by p1.cs.ohiou.edu (8.9.3/8.9.3) with SMTP id QAA12196; Thu, 26 Jul 2001 16:57:29 -0400 (EDT) Date: Thu, 26 Jul 2001 16:57:28 -0400 (EDT) From: Russell Francis X-Sender: frussell@p1 To: ustctsee@263.net Cc: freebsd-questions@FreeBSD.ORG Subject: Re: a programming question In-Reply-To: <3B602117.10121@mta6> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > dear hackers: > i meet a programming question,hope to get ur help! > now i want to get some process's concrete infomation with c language in > freebsd environment,example for whether the process exits or not , > and it's pid,ppid,status,cpu%,and so on.but i only know it's command > name.Is there a > function can do this?how to do it? > hope to receive ur answer!thanks very much! > your sincerely I am no expert, but I will perhaps point you in the right direction? I don't think that there is a way to specify the command name of a process and get information on it. Since many copies of the same program could be running this would cause some confusion. I assume you want to get the information about external processes as opposed to the process your program is running in? If this is the case, look into the kvm_getprocs(), kvm_openfiles() area. This family of functions should allow you to get information on all processes running. You could then search the list of processes for the command line string that started them as well as pid, ppid, %cpu, etc. and filter the output to your liking. If you have your system source installed a good place to look for examples of this approach is /usr/src/bin/ps.c & /usr/src/bin/ps.h This is the source to the familiar ps program. Hopefully this is a good start. Good Luck Russ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message