PSTAT Interfaces
17
int rv, count, fd;
fd = open("/etc/passwd", O_RDONLY);
rv = pstat_getfile2(&psf, sizeof(psf), 0, fd, getpid());
if (rv == 1) {
/*
* Ask for pathname information.
*/
count = pstat_getpathname(filename, 20, &(psf.psf_fid));
if (count > 0) {
if (strncmp("/etc/passwd", filename, count) == 0) {
printf("Success\n");
} else {
printf("Error encountered\n");
}
} else if (count == 0) {
printf("pathname not found in system cache\n");
} else {
perror("pstat_getpathname()");
}
} else {
perror("pstat_getfile2");
}
close(fd);
}
4.15 pstat_getproc()
Synopsis:
int pstat_getproc(struct pst_status *buf, size_t elemsize, size_t elemcount, int index);
Description:
This call returns information about active processes in the system. There is one instance
of this context for each active process on the system. For each instance, data up to a maximum
of elemsize bytes are returned in the structs pst_status pointed to by buf. The elemcount
parameter specifies the number of structs pst_status that are available at buf. The index
parameter specifies the starting index within the context of processes. As a shortcut, information
for a single process may be obtained by setting elemcount to zero and setting index to the PID of
that process.
Return Value:
This call returns –1 on failure or number of instances copied to buf on success.
Errors:
• EINVAL is set if the user's size declaration isn't valid.
• EINVAL is set if the initial selection, offset, isn't valid.
• ESRCH is set if the specific-PID shortcut is used and there is no active process with that PID.
• EFAULT is set if buf points to an invalid address.
Examples:
#include <sys/pstat.h>
/* Get information about all processes -- 10 at a time. */
void main(void)
{