From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 21 16:27:20 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2F70A16A508 for ; Wed, 21 Jul 2004 16:27:20 +0000 (GMT) Received: from creme-brulee.marcuscom.com (rrcs-midsouth-24-172-16-118.biz.rr.com [24.172.16.118]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7C70643D46 for ; Wed, 21 Jul 2004 16:27:19 +0000 (GMT) (envelope-from marcus@marcuscom.com) Received: from [192.168.1.4] (shumai.marcuscom.com [192.168.1.4]) i6LGQv9Q030829; Wed, 21 Jul 2004 12:26:57 -0400 (EDT) (envelope-from marcus@marcuscom.com) From: Joe Marcus Clarke To: Dan Nelson In-Reply-To: <20040721151220.GB42575@dan.emsphone.com> References: <1090378066.90026.105.camel@shumai.marcuscom.com> <20040721151220.GB42575@dan.emsphone.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-vwkcduZ6DhAn4TGXHxYZ" Organization: MarcusCom, Inc. Message-Id: <1090427233.29242.9.camel@shumai.marcuscom.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Wed, 21 Jul 2004 12:27:13 -0400 X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on creme-brulee.marcuscom.com X-Mailman-Approved-At: Thu, 22 Jul 2004 11:52:30 +0000 cc: hackers@freebsd.org Subject: Re: Getting a fully-qualified path from a PID X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2004 16:27:20 -0000 --=-vwkcduZ6DhAn4TGXHxYZ Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Wed, 2004-07-21 at 11:12, Dan Nelson wrote: > In the last episode (Jul 20), Joe Marcus Clarke said: > > What is the canonical way for a userland application to get the > > fully-qualified path of an executable from its running PID? I know I > > can do a readlink(2) on /proc/pid/file, but procfs is deprecated on > > 5.X, correct? Is there a more appropriate way to do this? Thanks. >=20 > realpath(argv[0]) works for commands not run from $PATH. Commands found > through a PATH earch will just have the basename in argv[0] so you > would have to check each PATH element until you found it. Note that > /proc/pid/file won't work if vn_fullpath() fails (say the orignal file > has been unlinked, or the filename has expired from the kernel's > cache). >=20 > If you are examining another process, you can use the kvm_getargv() and > kvm_getenvv() functions to fetch argv[0] and PATH out of the target > process. Okay, I was thinking about that. What I was specifically interested in was processes spawned from $PATH, so realpath isn't going to be much good to me there. I didn't know if there was a better way than getting the environ+argv with kvm, then searching each path element. Thanks for the clarification. Joe --=20 PGP Key : http://www.marcuscom.com/pgp.asc --=-vwkcduZ6DhAn4TGXHxYZ Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQBA/plhb2iPiv4Uz4cRAsVgAKCXkDIjXKLx3QwGv6xxIFCZulXcRQCfRlRj kS0GJ+63sDGBRnvpPPoIBb0= =36HK -----END PGP SIGNATURE----- --=-vwkcduZ6DhAn4TGXHxYZ--