#include <sys/ps.h> int w_getpsent(int processPos, struct w_psproc *bufferArea, size_t bufferLength);
w_getpsent
gets information about all processes
for which the caller is authorized.
The arguments to the w_getpsent
function are:
processPos
0
representing the first process. You
should call w_getpsent
from within a loop. On the first
call, pass a 0
as the processPos
argument, and w_getpsent
will return the position value of the next process that the calling
process has access to. This value is then used as the processPos
argument for the next call. Continue to loop until a 0
is returned.
bufferArea
bufferLength
w_psproc
structure, which is declared in <sys/ps.h>
. You may access
the following elements of this structure to obtain process
information:
unsigned int ps_state
pid_t ps_pid
pid_t ps_ppid
pid_t ps_sid
pid_t ps_pgpid
pid_t ps_fgpid
uid_t ps_euid
uid_t ps_ruid
uid_t ps_suid
gid_t ps_egid
gid_t ps_rgid
gid_t ps_sgid
long ps_size
time_t ps_starttime
clock_t ps_usertime
clock_t ps_systime
int ps_conttylen
char *ps_conttyptr
int ps_pathlen
char *ps_pathptr
int ps_cmdlen
char *ps_cmdptr
w_getpsent
returns an integer that identifies
the next process that the calling process has access to. A 0
is
returned to indicate that there are no more accessible processes.
A -1
is returned if the call to w_getpsent
is unsuccessful.
w_getpsent
function may be
useful in OpenEdition applications; however,
it is not defined by the POSIX.1 standard and should not be used
in portable applications.
w_getpsent
to
obtain process information:
#include <sys/types.h> #include <sys/ps.h> #include <stdio.h> #include <stdlib.h> #define MAX_CHAR 256 main() { int processNum = 0; W_PSPROC workArea; /* Initialize work area. */ memset(&workArea, 0, sizeof(workArea)); /* Allocate memory for character strings. */ if ((workArea.ps_conttyptr = (char *) malloc(MAX_CHAR)) == NULL) { perror("ps_conttyptr memory allocation error"); abort(); } else workArea.ps_conttylen = MAX_CHAR; if ((workArea.ps_pathptr = (char *) malloc(MAX_CHAR)) == NULL) { perror("ps_pathptr memory allocation error"); abort(); } else workArea.ps_pathlen = MAX_CHAR; if ((workArea.ps_cmdptr = (char *) malloc(MAX_CHAR)) == NULL) { perror("ps_cmdptr memory allocation error"); abort(); } else workArea.ps_cmdlen = MAX_CHAR; /* Get process information. */ do { processNum = w_getpsent(processNum, &workArea, sizeof(workArea)); if (processNum == -1) perror("error in w_getpsent"); else { printf("process number = %dn", processNum); printf("process ID = %10dn", workArea.ps_pid); printf("User ID = %8unn", workArea.ps_ruid); } } while (processNum != 0 && processNum != 1); }
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.