From owner-freebsd-questions Tue Sep 21 16:24:21 1999 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id 4FD2015408 for ; Tue, 21 Sep 1999 16:24:20 -0700 (PDT) (envelope-from bright@wintelcom.net) Received: from localhost (bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) with ESMTP id QAA17986; Tue, 21 Sep 1999 16:39:39 -0700 (PDT) Date: Tue, 21 Sep 1999 16:39:39 -0700 (PDT) From: Alfred Perlstein To: Ben Smithurst Cc: "Oleg V. Volkov" , freebsd-questions@FreeBSD.ORG Subject: Re: How to find absolute name of running binary? In-Reply-To: <19990921221532.A19388@lithium.scientia.demon.co.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Tue, 21 Sep 1999, Ben Smithurst wrote: > Alfred Perlstein wrote: > > > On Tue, 21 Sep 1999, Oleg V. Volkov wrote: > > > >> Well subject says it all. How could i find absolute name of my running > >> binary from inside it? References to man or C examples welcome. > > > > I think some permutation of getcwd(3) and argv[0] should help, perhaps > > with lstat (to check if you were run via a symlink) > > That won't do much if people give the program crap in argv[0], e.g. > execlp("foo", "ha ha, fooled you!", "-x", "-y", "z", NULL), will > it? There's some about this in some FAQ somewhere (comp.unix.programmer > FAQ maybe, I'm not sure), and it basically boils down to "don't > do it". I'd like to know what Oleg is doing and why he needs this > information. I even started looking at /proc/curproc/cmdline, but that removes the path components (or so it seems). Quite fustrating, but I'd love to hear from anyone who knows a way... -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message