- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Get full path of executable of running process...
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
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
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
тАО10-14-2008 02:39 AM
тАО10-14-2008 02:39 AM
Get full path of executable of running process...
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.
on Linux platforms i can do it by using following way.
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));
Here exepath gives us the full path of the executable.
Similarly for windows we do it using
GetModuleFileName(NULL, exepath, sizeof(exepath)); /* get fullpath of the service */
Please help me how to do it on HP-UX since there is no /proc directory in HP-UX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2008 02:56 AM
тАО10-14-2008 02:56 AM
Re: Get full path of executable of running process...
- Tags:
- pstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2008 05:12 AM
тАО10-14-2008 05:12 AM
Re: Get full path of executable of running process...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-14-2008 01:28 PM
тАО10-14-2008 01:28 PM
Re: Get full path of executable of running process...
- Tags:
- getcwd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2008 08:29 AM
тАО10-15-2008 08:29 AM
Re: Get full path of executable of running process...
Any help would be greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2008 08:41 AM
тАО10-15-2008 08:41 AM
Re: Get full path of executable of running process...
Stating the HP-UX *release* on which you are running would be useful. The 'pstat()' module has more functionality in newer releases than in older ones.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2008 09:14 AM
тАО10-15-2008 09:14 AM
Re: Get full path of executable of running process...
as a try I would set the s-bit for root on the executable, which uses the function pstat_getpathname() .
It depends on other stuff done by this program, if that is a security risk.
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-15-2008 12:20 PM
тАО10-15-2008 12:20 PM
Re: Get full path of executable of running process...
Sure you do, you just have to work smarter. :-)
Also, if you were using a real shell the variable "_" would have the relative or absolute path of the executable. sh may not have the "./".
>directly with some system function
No such function for ordinary users.
This program only shows you how to get argv:
#include
#include
#include
#if defined(__LP64__) || defined(__ia64)
#define ARGVS __argv
#else
extern char **__argv_value;
#define ARGVS __argv_value
#endif
int main() {
int i;
const char *path = getenv("PATH");
printf("PATH=%s\n", path);
for (i = 0; ARGVS[i]; ++i) {
printf("argv[%03d]: %s\n", i, ARGVS[i]);
}
for (i = 0; _environ[i]; ++i) {
printf("env[%03d]: %s\n", i, _environ[i]);
}
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2008 04:17 AM
тАО10-16-2008 04:17 AM
Re: Get full path of executable of running process...
Signature of pstat_getpathname
int pstat_getpathname(
char *buf,
size_t elemcount,
struct pst_fid *fid
);
I see the man page of pstat_getpathname() which states we can use pstat_getfile2() or pstat_getproc() to obtain fid. but when i see signature of pstat_getproc then it takes struct pst_status as an argument. how to get the fid from struct pst_status variable.
from pstat_getfile2 things works, but i need to open the file to get this details (which i dont have).
Thanks in advance...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2008 12:37 PM
тАО10-16-2008 12:37 PM
Re: Get full path of executable of running process...
You don't know the name and it isn't open. So you are left with getcwd()/argv[0].
I suppose you could use shl_get(3) or dlget(3) and then use advanced AI technology to figure out which is the executable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-16-2008 04:49 PM
тАО10-16-2008 04:49 PM
Re: Get full path of executable of running process...
Ok, shl_get(3) says use index of -2, unfortunately that only gives the relative path if invoked with one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2008 01:00 AM
тАО11-14-2008 01:00 AM
Re: Get full path of executable of running process...
pst.pst_pid = -1;
pstat_getproc (&pst, sizeof (pst_status), 0, getpid());
char pathbuffer[1024];
pstat_getpathname(pathbuffer,1024,&pst.pst_fid_text);
printf("Executable full path:%s\n",pathbuffer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-14-2008 02:58 AM
тАО11-14-2008 02:58 AM
Re: Get full path of executable of running process...
Yes, this solution was alluded to in rakeshcs123's other thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1280356
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-15-2008 07:42 AM
тАО11-15-2008 07:42 AM