Virtually the best blog on the web!
Finding the Absolute Path of a Running Process
A friend of mine recently asked me about finding the absolute command path of a process given the pid. Ofcourse, it’s very easy to do it for a particular OS. Doing it platform independently is actually a little tough. There’s no straight-forward POSIXy way of doing this (as far as I know). One can certainly do some /proc magic, but that won’t be portable. My suggestion was to just use ps. This works for both Solaris and Linux. So, you get the output from
ps -p <pid> -f UID PID PPID C STIME TTY TIME CMD draganm 17198 17193 0 20:40:40 ? 0:00 csh -c /usr/lib/ssh/sftp-server
and simply do some string manipulation to get the required string (shown in bold above). Any other ideas folks?
| Print article | This entry was posted by Pradeep Padala on October 26, 2005 at 11:06 pm, and is filed under Open Source, Tips. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |