Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jul 2001 16:57:28 -0400 (EDT)
From:      Russell Francis <frussell@p1.cs.ohiou.edu>
To:        ustctsee@263.net
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: a programming question
Message-ID:  <Pine.GSO.3.96.1010726164425.10390A-100000@p1>
In-Reply-To: <3B602117.10121@mta6>

next in thread | previous in thread | raw e-mail | index | archive | help

> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.3.96.1010726164425.10390A-100000>