- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Need a C function to retrieve currently execut...
Operating System - HP-UX
1748163
Members
3727
Online
108758
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
тАО03-29-2001 01:56 PM
тАО03-29-2001 01:56 PM
I have not found any C function or routine to get the currently executing file for a given process I.D. getrusage seems to be the closest I have, but I am unsure as I haven't found the structure of the rusage struct in the docs.
Can anyone recommend a function to retrieve this when given the process I.D.?
Thanks.
Can anyone recommend a function to retrieve this when given the process I.D.?
Thanks.
"Our problems are manmade; therefore they can be solved by man." - JFK
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2001 01:44 AM
тАО03-30-2001 01:44 AM
Re: Need a C function to retrieve currently executing file for a process
The simple is that there is no "reliable" way of getting the executable file name from the process ID. It is worth having a look at the thread "Retrieving program name" in the HPUX-DEVTOOLS mailing list (use thread name in the search at http://devresource.hp.com). This discusses some of the options and contains an elaborate program for finding a valid filename if possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2001 04:19 AM
тАО03-30-2001 04:19 AM
Re: Need a C function to retrieve currently executing file for a process
Well, there got to be a way to retrieve the name. With lsof, if a process id was given in the parameter then all actively opened files will be listed, and that binary file which the process started from is listed too.
If you have access to the lsof command source, browse through it and you may find what you want there.
~Philip
If you have access to the lsof command source, browse through it and you may find what you want there.
~Philip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2001 04:37 AM
тАО03-30-2001 04:37 AM
Solution
Try this one:
#include
struct pst_status ps;
int pid;
/* determine the pid somewhere before here...*/
if ( pst_getstatus( &ps, sizeof(ps), 0, pid ) < 0 ) {
perror( "Cannot get status" );
return -1;
}
printf( "Process command line = %s\n", ps.pst_command );
printf( "Process base name = %s\n", pst.pst_ucomm );
Further information can be found in the man page for pstat(2).
I hope this helps.
#include
struct pst_status ps;
int pid;
/* determine the pid somewhere before here...*/
if ( pst_getstatus( &ps, sizeof(ps), 0, pid ) < 0 ) {
perror( "Cannot get status" );
return -1;
}
printf( "Process command line = %s\n", ps.pst_command );
printf( "Process base name = %s\n", pst.pst_ucomm );
Further information can be found in the man page for pstat(2).
I hope this helps.
I think, therefore I am... I think!
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP