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



Relevant Pages

  • Re: How to get a process working directory in HP-UX system
    ... Our code need get to know the working directory of given process based ... specific pid. ... The first line should have the FD of 'cwd' and be your current working ... Posted via a free Usenet account from http://www.teranews.com ...
    (comp.sys.hp.hpux)
  • Re: 7.1RC1: system hang
    ... pid ppid pgrp uid state wmesg wchan cmd ... Tracing command vmstat pid 96381 tid 100276 td 0xc756caf0 ...
    (freebsd-stable)
  • Re: how to delete a DLL beeing used by windows?
    ... ListDLLs V2.23 - DLL lister for Win9x/NT ... WINLOGON.EXE pid: 164 ... Command line: winlogon.exe ... > "Dimitriy Braslavskiy" wrote in message ...
    (microsoft.public.win2000.security)
  • Re: IPC
    ... You want to use the system command here ... ... Pid in perl script are different from Pid in bash and so I can't kill them and I can't wait for them. ... 19992 pts/1 00:00:00 example.pl ... 20001 pts/1 00:00:00 sh child process 19993 finished, ...
    (comp.lang.perl.misc)
  • Re: Wait for background processes to complete
    ... trying to use the shell concepts and maximize parallelism). ... the systemcommand - which leaves us back at square one. ... fork, and then do your own wait. ... PID PGID COMMAND ...
    (comp.lang.perl.misc)