Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:25:31+00:00 2026-05-15T19:25:31+00:00

Suppose you run the application ‘app’ by typing ‘app’, rather than its absolute path.

  • 0

Suppose you run the application ‘app’ by typing ‘app’, rather than its absolute path. Due to your $PATH variable, what actually runs is /foo/bar/app. From inside app I’d like to determine /foo/bar/app. argv[0] is just ‘app’, so that doesn’t help.

I know in Linux I can get look at the

/proc/self/exe

softlink, but that doesn’t work on other *nix, specifically OS X. Is there a more portable way to determine the dir in which the app lives?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:25:31+00:00Added an answer on May 15, 2026 at 7:25 pm

    I ended up mimicking the ‘which’ program and looking at each dir in $PATH to see if $dir/app is executable:

    if (strchr(progname, '/') == NULL) {
        std::string pathStr = getenv("PATH");
        std::string testDir;
        pathStr += ":";             // add a trailing ':' to make search easier
        size_t pos = 0;
        bool found = false;
    
        while (!found && ((pos = pathStr.find(":")) != std::string::npos)) {
          testDir = pathStr.substr(0, pos);
          testPath = testDir + "/" + progname;
          pathStr = pathStr.substr(pos + 1, pathStr.size() - pos + 1);
          if (access(testPath.c_str(), X_OK) == 0)
            found = true;
        }
        if (found)
          dir = testDir.c_str();
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I run an application, after some time this app will get closed by
Possible Duplicate: Run one instance from the application let's suppose i make an application
Suppose you were writing a network-based WinForms application which is supposed to run in
Suppose in your web application you need to do a number of redis calls
Suppose I have a .Net Framework 3.5 SP1/CLR 2.0 application which needs to run
Suppose that my application has many processes. I try to run some init code
Suppose: users need to log-in account to run the application and buy apps items.
I'm having working on a Rails application that is supposed to run on an
So I'm writing a program that is suppose to run forever (client server stuff)
I have a requirement such that my program is suppose to run for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.