Re: Getting a fully-qualified path from a PID
From: Dan Nelson (dnelson_at_allantgroup.com)
Date: 07/21/04
- Previous message: Devon H. O'Dell: "Re: "Next Generation" kernel configuration?"
- In reply to: Joe Marcus Clarke: "Getting a fully-qualified path from a PID"
- Next in thread: Joe Marcus Clarke: "Re: Getting a fully-qualified path from a PID"
- Reply: Joe Marcus Clarke: "Re: Getting a fully-qualified path from a PID"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Jul 2004 10:12:20 -0500 To: Joe Marcus Clarke <marcus@marcuscom.com>
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.
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).
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.
-- Dan Nelson dnelson@allantgroup.com _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
- Previous message: Devon H. O'Dell: "Re: "Next Generation" kernel configuration?"
- In reply to: Joe Marcus Clarke: "Getting a fully-qualified path from a PID"
- Next in thread: Joe Marcus Clarke: "Re: Getting a fully-qualified path from a PID"
- Reply: Joe Marcus Clarke: "Re: Getting a fully-qualified path from a PID"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]