Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Mar 96 13:45:03 MET
From:      Greg Lehey <lehey.pad@sni.de>
To:        terry@lambert.org (Terry Lambert)
Cc:        hackers@freebsd.org (Hackers; FreeBSD)
Subject:   Re: Weird problem.
Message-ID:  <199603111248.NAA19735@nixpbe.pdb.sni.de>
In-Reply-To: <199603092059.NAA21396@phaeton.artisoft.com>; from "Terry Lambert" at Mar 9, 96 1:59 pm

next in thread | previous in thread | raw e-mail | index | archive | help
>
>> > Given the pid of a process, is there any way of finding the executable
>> > file (including complete path) of this process?
>>
>> This is one of the Unix FAQs.  No, it's not possible, and nobody could
>> even guarantee you that the pathname is still available.  If you don't
>> believe it, consider the following:
>>
>> 	./foo & rm -f foo
>
> Well, if it hasn't been deleted, it's possible.

That depends.  Consider this one:

ln foo bar
bar &

If I go back searching the directory structure for the inode number,
I'm more likely to find foo than bar.  Sure, it's the correct file,
but it's the wrong name.

I suppose you could look at argv [0], but there's no guarantee that
the process hasn't changed it.

> But of course, by the time the reverse lookup is complete, it has
> probably finished running anyway (it's very time consuming, but
> there is nothing preventing you from writing a program to do it for
> you).

Again, that depends.  I have plenty of processes which run for days.
It shouldn't take *that* long to search the directory tree.

Greg



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603111248.NAA19735>