Re: How to get a process working directory in HP-UX system
- From: Vishwas Pai <noname@xxxxxxxxxxxxxx>
- Date: Fri, 09 Nov 2007 08:22:59 +0530
Wu Ting Bin wrote:
Hi all,
Our code need get to know the working directory of given process based
specific pid. Could anyone give me a hand to give me informations?
Following code assumes that current working directory
is found in lookup cache (assumption is in pstat_getpathname).
Please use this snip at your risk as this may not work in
all situations..
--vishwas.
--
#include <sys/pstat.h>
#include <sys/param.h>
#include <fcntl.h>
#include <stdio.h>
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 <pid>\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);
}
}
.
- References:
- How to get a process working directory in HP-UX system
- From: Wu Ting Bin
- How to get a process working directory in HP-UX system
- Prev by Date: Re: Help! problem : error is/usr/lib/hpux32/dld.so: Unable to find library 'libperl.so'
- Next by Date: CDE on hpux 11.11
- Previous by thread: How to get a process working directory in HP-UX system
- Next by thread: Re: How to get a process working directory in HP-UX system
- Index(es):
Relevant Pages
|