Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: Program name from PID? Message-ID: <1991Feb15.161615.11166@convex.com> Date: 15 Feb 91 16:16:15 GMT References: <59@rscsys.UUCP> <1991Feb15.051742.7799@convex.com> <1991Feb15.125634.2727@en.ecn.purdue.edu> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: usa Organization: CONVEX Software Development, Richardson, TX Lines: 30 Nntp-Posting-Host: pixel.convex.com From the keyboard of longshot@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@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)