PSTAT Interfaces
9
Example:
List all the open files for the parent process.
#include <sys/pstat.h>
void main(void)
{
#define BURST ((size_t)10)
pid_t target = getppid();
struct pst_fileinfo2 psf[BURST];
int i, count;
int idx = 0; /* index within the context */
printf("Open files for process ID %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++) {
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()");
}
4.7 pstat_getfiledetails()
Synopsis:
int pstat_getfiledetails(struct pst_filedetails *buf, size_t elemsize, struct pst_fid *fid);
Description:
This call provides detailed information about a particular open file. For each call, data up
to a maximum of elemsize bytes are returned in the struct pst_filedetails pointed to by buf. The
fid parameter uniquely identifies the file. This fid is obtained from calls to pstat_getfile2(),
pstat_getproc(), or pstat_getprocvm(). The pst_filedetails structure contains information
equivalent to the stat(2) call. Use of this function is limited to UID == 0 or effective UID match.
Effective UID match occurs when the effective or real UID of the calling thread matches the
effective or real UID of the target process and the target process has not done a set[u/g]id.
The structure members psfd_mode, psfd_ino, psfd_dev, psfd_uid, psfd_gid, psfd_atime,
psfd_mtime, psfd_ctime will have meaningful values for regular files, character or block special
files, and pipes. The value of the member psfd_nlink will be set to number of links to the file.
The member psfd_rdev will have meaningful value for character or block special files, while the
psfd_size is valid for regular files. Psfd_hi_fileid, psfd_lo_fileid, psfd_hi_nodeid, and