- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: current working directory of process
Operating System - Linux
1753562
Members
6134
Online
108796
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
тАО02-21-2008 06:49 AM
тАО02-21-2008 06:49 AM
hi all,
i want to get current working directory for all processes. i am using pstat_ system calls to fetch those information.But the pstat_ calls nowhere return current directory of a process. Can anyone suggest me?
Regards,
sanjay
i want to get current working directory for all processes. i am using pstat_ system calls to fetch those information.But the pstat_ calls nowhere return current directory of a process. Can anyone suggest me?
Regards,
sanjay
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 07:07 AM
тАО02-21-2008 07:07 AM
Re: current working directory of process
Hi:
An individual process can use 'getcwd()' to obtain its *own* current working directory [of course].
I don't believe that there is a way (in HP-UX at least) to fetch this information otherwise, though. For that matter, why would you want to do so?
Regards!
...JRF...
An individual process can use 'getcwd()' to obtain its *own* current working directory [of course].
I don't believe that there is a way (in HP-UX at least) to fetch this information otherwise, though. For that matter, why would you want to do so?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-21-2008 06:58 PM
тАО02-21-2008 06:58 PM
Solution
Following code assumes that current working directory
is found in lookup cache (assumption is in pstat_getpathname). So it may not may not work in all situations..
--vishwas.
--
#include
#include
#include
#include
main(int argc , char **argv)
{
struct pst_status pst[1];
int count;
char buf[MAXPATHLEN+1];
pid_t pid;
if ( argc != 2 ) {
printf("Usage: pwdx\n");
exit(1);
}
pid = atol (argv[1]);
if ( getppid(pid) < 0 ) {
fprintf(stderr,"Error: %s %d is not a valid pid.\n",
argv[1],pid);
exit(1);
}
bzero(buf,MAXPATHLEN+1);
if ( (count=pstat_getproc(pst, sizeof(pst[0]), 0, pid )) > 0 ) {
printf("pid is %d, command is %s\n",
pst[0].pst_pid, pst[0].pst_ucomm);
}
count = pstat_getpathname(buf,MAXPATHLEN,&pst[0].pst_fid_cdir);
if (count > 0) {
printf("%s\n", buf);
exit(0);
}
else {
fprintf(stderr,"ERROR getting the CWD.\n");
perror("pstat_getpathname");
exit(1);
}
}
is found in lookup cache (assumption is in pstat_getpathname). So it may not may not work in all situations..
--vishwas.
--
#include
#include
#include
#include
main(int argc , char **argv)
{
struct pst_status pst[1];
int count;
char buf[MAXPATHLEN+1];
pid_t pid;
if ( argc != 2 ) {
printf("Usage: pwdx
exit(1);
}
pid = atol (argv[1]);
if ( getppid(pid) < 0 ) {
fprintf(stderr,"Error: %s %d is not a valid pid.\n",
argv[1],pid);
exit(1);
}
bzero(buf,MAXPATHLEN+1);
if ( (count=pstat_getproc(pst, sizeof(pst[0]), 0, pid )) > 0 ) {
printf("pid is %d, command is %s\n",
pst[0].pst_pid, pst[0].pst_ucomm);
}
count = pstat_getpathname(buf,MAXPATHLEN,&pst[0].pst_fid_cdir);
if (count > 0) {
printf("%s\n", buf);
exit(0);
}
else {
fprintf(stderr,"ERROR getting the CWD.\n");
perror("pstat_getpathname");
exit(1);
}
}
- Tags:
- threads corrupted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-22-2008 03:00 AM
тАО02-22-2008 03:00 AM
Re: current working directory of process
Thanks for the support. we get the current directory from struct pst_status in where the field struct __pst_fid pst_fid_cdir;/* Cookie for current working directory */ gives the current working directory for a process.
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