title: Can an executable discover its own path? (Linux)
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/933850/how-to-find-the-location-of-the-executable-in-c">how to find the location of the executable in C</a>  </p>
  </blockquote>
  
  
  
  <p>I would like an executable to be able to discover its own path; I have a feeling that the answer is "you can't do this", but I would like this to be confirmed!</p>
  
  <p>I don't think I can use <code>getcwd()</code>, because I might not be executing it from the same directory.  I don't think I can use <code>argv[0]</code>, because that is based on the string that's used to execute it.  Are there any other options?</p>
  
  <p><strong>Rationale</strong></p>
  
  <p>The real problem is that I'd like to place an executable somewhere on a filesystem, and place a default config file alongside it.  I want the executable to be able to read its config file at runtime, but I don't want to hardcode this location into the executable, nor do I want the user to have to set environment variables.  If there's a better solution to this situation, I'm all ears...</p>