Here's a project: which
I haven't looked at the source to see how complicated it is, but it's a place to start. Using which
will tell you the path to an executable found in your PATH.
If the program was executed with a path at the command line (for example: "/home/progs/cool1/start" or "../../progs/cool1/start") then argv ought to contain the path provided as well as the executable name.
I have some code that turns a relative path (e.g. "../../progs/cool1/start") into an absolute path by combining the current working directory with the relative path and then applying effects of the "up-dir" references.