This is a discussion on How to get a process working directory in HP-UX system within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> Hi all, Our code need get to know the working directory of given process based specific pid. Could anyone ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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? This is a problem I can not get from google search. Thank you very much |
| |||
| 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); } } |
| |||
| "Wu Ting Bin" <wutingbin@gmail.com> wrote in message news:1194426153.123297.225880@19g2000hsx.googlegro ups.com... > 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? > > This is a problem I can not get from google search. > > Thank you very much > Try lsof (with -p pid) available from http://hpux.cs.utah.edu/ The first line should have the FD of 'cwd' and be your current working directory. -- Posted via a free Usenet account from http://www.teranews.com |
| |||
| On 11月9日, 上午10时52分, Vishwas Pai <non...@noland..invalid> wrote: > Wu Ting Bin wrote: > > Hi all, > > > Our code need get to know theworkingdirectoryof given process based > > specific pid. Could anyone give me a hand to give me informations? > > Following code assumes that currentworkingdirectory > 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); > } > > > > }- 隐藏被引用文字 - > > - 显示引用的文字 - It works. Thanks. |
| ||||
| On 11月19日, 上午10时18分, "Kilgaard" <Kilga...@hotmail.com> wrote: > "Wu Ting Bin" <wuting...@gmail.com> wrote in messagenews:1194426153.123297..225880@19g2000hsx.g ooglegroups.com... > > > Hi all, > > > Our code need get to know theworkingdirectoryof given process based > > specific pid. Could anyone give me a hand to give me informations? > > > This is a problem I can not get from google search. > > > Thank you very much > > Try lsof (with -p pid) available fromhttp://hpux.cs.utah.edu/ > > The first line should have the FD of 'cwd' and be your currentworkingdirectory. > > -- > Posted via a free Usenet account fromhttp://www.teranews.com You are right. But I can not install lsof tool in that machine. Thank you too. |