Aqcuiring full path to running process from outside the kernel

Dag-Erling Smørgrav des at des.no
Mon Aug 21 10:43:49 UTC 2006


Mike Meyer <mwm-keyword-freebsdhackers2.e313df at mired.org> writes:
> However, you can also make a best effort. Check argv[0] to see if you
> have an absolute path. If not, do what the shell would do to find the
> executable - look for it on $PATH. Once you've found it, call
> realpath(3) to canonicalize the path.

You got it the wrong way around.  First pass argv[0] to realpath(3),
fall back to using $PATH only if realpath(3) fails (which it shouldn't
unless you've called chdir(2), chroot(2) or jail(2) earlier in the
process, or the executable was moved or removed)

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list