<p>I want to get the full path of the running process (executable) without having root permission using C++ code. Can someone suggest a way to achieve this.</p>

<p>on Linux platforms i can do it by using following way.</p>

<pre><code>char exepath[1024] = {0};
char procid[1024] = {0};
char exelink[1024] = {0};

sprintf(procid, "%u", getpid());

strcpy(exelink, "/proc/");
strcat(exelink, procid);
strcat(exelink, "/exe");

readlink(exelink, exepath, sizeof(exepath));
</code></pre>

<p>Here exepath gives us the full path of the  executable.</p>

<p>Similarly for windows we do it using </p>

<pre><code>GetModuleFileName(NULL, exepath, sizeof(exepath));  /* get fullpath of the service */
</code></pre>

<p>Please help me how to do it on HP-UX since there is no /proc directory in HP-UX.</p>

I have done this before in a general case.  The general idea is to grab argv[0], and do some processing on it:
```
```
int main( int argc, char** argv )
{
  string full_prog_path = argv[0];
  if ( full_prog_path[0] == "/" )
  {   // It was specified absolutely; no processing necessary.
  }
  else
  {
    string check_cwd = getcwd();
    check_cwd += argv[0];
    if ( FileExists( check_cwd ) )
    { // It was specified relatively.
      full_prog_path = check_cwd;
    }
    else
    { // Check through the path to find it
      string path = getenv( "PATH" );
      list<string> paths = path.split( ":" );
      foreach( test_path, paths )
      {
        if ( FileExists( test_path + argv[0] ) )
        { // We found the first path entry with the program
          full_prog_path = test_path + argv[0];
          break;
        }
      }
    }
  }

  cout << "Program path: " << full_prog_path << endl;

  return 0;
}
```
```
Obviously, this has some assumptions that might break at some point, but it should work for most cases.