How to get a process working directory in HP-UX system - HP UX

This is a discussion on How to get a process working directory in HP-UX system - HP UX ; 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 ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: How to get a process working directory in HP-UX system

  1. How to get a process working directory in HP-UX system

    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


  2. Re: How to get a process working directory in HP-UX system

    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
    #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);
    }
    }

  3. Re: How to get a process working directory in HP-UX system

    "Wu Ting Bin" 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


  4. Re: How to get a process working directory in HP-UX system

    On 11月9日, 上午10时52分, Vishwas Pai 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
    > #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);
    > }
    >
    >
    >
    > }- 隐藏被引用文字 -
    >
    > - 显示引用的文字 -


    It works. Thanks.

  5. Re: How to get a process working directory in HP-UX system

    On 11月19日, 上午10时18分, "Kilgaard" wrote:
    > "Wu Ting Bin" 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.

+ Reply to Thread