#include <sys/param.h>
#include <sys/pstat.h>
#include <sys/unistd.h>
#include <stdio.h>
int main( int argc, char *argv[] )
{
#define BURST ((size_t)10)
struct pst_fileinfo2 psf[BURST];
int i, count;
int idx = 0; /* index within the context */
if ( argc != 2 )
{
printf( "args: <pid>\n" );
exit( 1 );
}
pid_t target = atoi( argv[1] );
(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
} |