Path: utzoo!attcan!telly!lethe!tvcent!comspec!humvax!becker!hybrid!scifi!bywater!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.questions Subject: Re: Program name from PID? Message-ID: <6110@auspex.auspex.com> Date: 17 Feb 91 23:34:28 GMT References: <1991Feb15.051742.7799@convex.com> <1991Feb15.125634.2727@en.ecn.purdue.edu> <1991Feb15.161615.11166@convex.com> Distribution: usa Organization: Auspex Systems, Santa Clara Lines: 26 >On a Sun, it looks like you can use kvm_getu() from libkvm.a . "kvm_getu()" gets the U area of the process, which contains "u_comm", which is one of the possible "names" of the process. The other possible "name" is the command and arguments for the process, which can be obtained with "kvm_getcmd()". >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. Later System V systems store a character string fabricated from the arguments passed in an "exec()" in "u_psargs". "u_comm" is there in AT&T S5 releases as well. The systems I'd worry about are the ones not derived from AT&T source, or at least the ones where the lower levels of the system aren't derived from AT&T source. (Enough of older BSD systems is sufficiently derived from AT&T source; 4.3-reno's U area isn't AT&T-derived - or, at least, "user.h" has the "AT&T-free" copyright notice - and it does *not* have anything like "u_comm"; it stores that information in the proc structure instead.) I think S5R4's "/proc" file system lets you fetch that string without having to fetch the user structure yourself.