Program name from PID?

Tom Christiansen tchrist at convex.COM
Sat Feb 16 03:16:15 AEST 1991


>From the keyboard of longshot at en.ecn.purdue.edu (Longshot (tm)):
:	The question:  How can you look up a process name (or partial name
:  possibly wild cards, or just a short version) in kmem?  ie how do I get
:  the corresponding PID(s)? I don't have the time or patience to look through 
:  'ps' so any suggestions will be appreciated.  

Short-cuts to knowledge don't buy you as much as the longer, more
interesting route.  It's like the difference between memorizing
formulae and knowing how they were derived.  With the first method,
a memory fault will leave you up a crick without a paddle.  The second
gives you a chance to re-create the holes.

If you want a short answer and are running on either a Convex or a Sun,
there are functions in the lib(k)vm libraries to do this for you, and
they're quite quick as they map in the space.   On a Convex, use
Getuproc() from libvm.a, or simply Getproccmd() (which is what you want)
from the same library.  On a Sun, it looks like you can use kvm_getu()
from libkvm.a .

Otherwise, you're going to have to nlist the kernel to find the proc
structure, use that to find your pid's proc entry, then use the pointer
there to go find the corresponding user structure, and then there you'll
find the command name.  Of course, all this assumes a fairly standard
looking kernel -- I've not tried it on anything that's not a BSD system,
i.e. Suns, Vaxen, and Convexen.

--tom
--
Tom Christiansen		tchrist at convex.com	convex!tchrist
 "All things are possible, but not all expedient."  (in life, UNIX, and perl)



More information about the Comp.unix.questions mailing list