HP-UX Reference (11i v1 00/12) - 2 System Calls (vol 5)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man2/!!!intro.2
________________________________________________________________
___ ___
p
pstat(2) pstat(2)
/*
* Example 6: List all the open files for the parent process
*/
{
pid_t target = getppid();
#define BURST ((size_t)10)
struct pst_fileinfo2 psf[BURST];
int i, count;
int idx = 0; /* index within the context */
(void)printf("Open files for process PID %d\n", target);
/* loop until all fetched */
while ((count = pstat_getfile2(psf, sizeof(struct pst_fileinfo2),
BURST, idx, target)) > 0) {
/* process them (max of BURST) at a time */
for (i = 0; i < count; i++) {
(void)printf("fd #%d\tFSid %x:%x\tfileid %d\n",
psf[i].psf_fd,
psf[i].psf_id.psf_fsid.psfs_id,
psf[i].psf_id.psf_fsid.psfs_type,
psf[i].psf_id.psf_fileid);
}
/*
* Now go back and do it again, using the
* next index after the current ’burst’
*/
idx = psf[count-1].psf_fd + 1;
}
if (count == -1)
perror("pstat_getfile2()");
#undef BURST
}
/*
* Example 7: Acquire information about a specific LWP
*/
{
struct lwp_status lwpbuf;
/*
* get information for LWP whose lwpid is 4321 within
* a process whose pid is 1234.
*/
count = pstat_getlwp(buf, sizeof(struct lwp_status),
0, 4321, 1234)
if (count == -1)
perror("pstat_getlwp()");
else
...
}
/*
* Example 8: Acquire detailed information about a specific file
*/
main()
{
struct pst_fileinfo2 psf;
struct pst_filedetails psfdetails;
int count, fd;
fd = open("/stand/vmunix", O_RDONLY);
count = pstat_getfile2(&psf, sizeof(psf), 0, fd, getpid());
HP-UX Release 11i: December 2000 12 Section 2229
___
___