- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- C++ App determining full path of executable
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 06:59 AM
04-05-2002 06:59 AM
C++ App determining full path of executable
I've got a set of apps which I've ported to Linux & Solaris, and I've almost got them completely ported to HP-UX 11i using aCC. There's one last roadblock I've hit.
My apps need to be able to figure out where the executable being run is actually located (since the executable could be started by name via a PATH search, or "./appname", or...) I need to find the COMPLETE path to the running executable from WITHIN the executable.
In Linux I can read the link at /proc/PID/exe, while in Solaris I read the info from /proc/PID/psinfo (where PID is the current process ID from getpid()). Any ideas how I can do the same thing on HP-UX with an aCC app? Thanks in advance.
Allan Stirrett.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:13 AM
04-05-2002 07:13 AM
Re: C++ App determining full path of executable
Try whereis.
whereis grep | awk '{print $2}'
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:17 AM
04-05-2002 07:17 AM
Re: C++ App determining full path of executable
Another option is to sh out to / and do a search for it, holding the result in a string.
or
During the install/porting track where the executable was placed and then transfer that to your programme.
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:25 AM
04-05-2002 07:25 AM
Re: C++ App determining full path of executable
When I've needed to do this in a completely portable way and not rely upon the vagaries of a particular OS, I've found that the most reliable and portable way is to do it myself.
1) Check argv[0] - does it begin with a '/'? If so, you have your answer otherwise,
2) Call getenv() to get PATH and then parse PATH for each component. Test each component directoiry in turn for the existence of the concated pathname string "path_component/argv[0]". The first match is your answer.
This method is a little tedious but it works anywhere.
Regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:43 AM
04-05-2002 07:43 AM
Re: C++ App determining full path of executable
That's sort of what I'm thinking might be my only alternative if I can't find a more "neato" way of doing this on HP.
One addition to your suggestion (since I've already implemented this as a temporary solution): If argv[0] does NOT start with a "/" but DOES start with ".", paste a getcwd() onto the front of argv[0] and filter out the "../"'s (ie. /usr/local/myapp/etc (getcwd) + ../../bin/myexe (argv[0]) becomes /usr/local/bin/myexe). Failing that, run through PATH and see where it's located as you mentioned.
The reason I'm still looking for something better is:
1) where I do the executable path lookup is actually deep inside one of my own shard libraries, where I do not have access to argv[0]. Thus, I must rely on any executables using that library to set some GLOBAL argv/argc's for my library to use (ewww!)
2) I have a bad feeling there could be a way that an executable could be launched and NOT be found by the three steps you & I worked out (ie. not /path..., not ../../....., not in PATH)--I hope I'm wrong. The Linux & Solaris methods are a bit more foolproof that way (ie. the info they use is ALWAYS guaranteed to be there).
Thank you very much for the suggestion.
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:43 AM
04-05-2002 07:43 AM
Re: C++ App determining full path of executable
Futher to Clay's suggestion - once you have found the path to the execuatable, store it so you do not have the search to do again.
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-05-2002 07:49 AM
04-05-2002 07:49 AM
Re: C++ App determining full path of executable
Yes, DEFINITELY! I do the executable location lookup quite often in the program. Especially if I'm going to do the manual PATH parsing, I don't want to have to do it more than once, so I keep it in a global buffer along with a global bool which keeps track of whether I've done the lookup already. Thanks for the tip!
Allan.