w_getpsent -- Get Process Information


 #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:
is an integer that identifies the relative position of a process within the system, with a 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.
is a pointer to a buffer area that is used to store information about the processes.
is the length in bytes of the buffer area.
The information about a process is stored in a 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
process state
pid_t ps_pid
process identification
pid_t ps_ppid
process parent identification
pid_t ps_sid
session identification
pid_t ps_pgpid
process group identification
pid_t ps_fgpid
foreground process group identification
uid_t ps_euid
effective user identification
uid_t ps_ruid
real user identification
uid_t ps_suid
saved user identification
gid_t ps_egid
effective group identification
gid_t ps_rgid
real group identification
gid_t ps_sgid
saved set group identification
long ps_size
total size
time_t ps_starttime
start time
clock_t ps_usertime
user CPU time
clock_t ps_systime
system CPU time
int ps_conttylen
controlling terminal name length
char *ps_conttyptr
controlling terminal name
int ps_pathlen
length of pathname
char *ps_pathptr
int ps_cmdlen
length of command
char *ps_cmdptr
command and arguments


If successful, 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.


The 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.


The following example illustrates the use of w_getpsent to obtain process information:
  #include <sys/types.h>
  #include <sys/ps.h>
  #include <stdio.h>
  #include <stdlib.h>

  #define MAX_CHAR 256

     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");
        workArea.ps_conttylen = MAX_CHAR;

     if ((workArea.ps_pathptr = (char *) malloc(MAX_CHAR)) == NULL) {
        perror("ps_pathptr memory allocation error");
        workArea.ps_pathlen = MAX_CHAR;

     if ((workArea.ps_cmdptr = (char *) malloc(MAX_CHAR)) == NULL) {
        perror("ps_cmdptr memory allocation error");
        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.