Fetch prpsinfo structure

Fetch prpsinfo structure

Post by John Stran » Thu, 29 Jun 1995 04:00:00

Would someone post or mail me some code to fetch the prpsinfo
structure defined in man proc. My attempt feteched me a device busy.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/file.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/fault.h>
#include <sys/syscall.h>
#include <sys/procfs.h>
#include <unistd.h>
#include <sys/open.h>
#include <sys/cred.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>

int main (int argc, char *argv[] )
        char    pid_fn [40] ;
        int     pid_fs ;
const struct    prpsinfo *prps_info ;
        int     rtn_code ;

        sprintf (pid_fn, "/proc/%d", getpid() ) ;

        pid_fs = open (pid_fn, FREAD) ;
        if (pid_fs == -1)
          exit (errno) ;

        rtn_code = ioctl (pid_fs, PIOCPSINFO, prps_info) ;

        printf ("%s\n", prps_info->pr_fname[PRFNSZ]) ;

        return (0) ;

Quote:} /* end main */

This posting represents the personal opinions of the author. It is not the
official opinion or policy of the author's employer. Warranty expired when you
opened this article and I will not be responsible for its contents or use.

1. prpsinfo structure

        I want to collect process statistics and report them in the way
that ps does it. I can fill up a prpsinfo_t structure through an
ioctl call. However, I have trouble interpreting the meaning of the
following fields. Basically, I can not match values returned by
the ps command with the values reported in the fields of the
prpsinfo_t structure.

pr_size  : size of process image in pages
- Does it include text, stack, and heap?

pr_rssize: resident set size in pages
- Does it include text, stack, and heap?

pr_cpu   : pre-SVR4, cpu usage for scheduling
- How can I map this value to an actual %CPU usage?

pr_pctcpu: % of recent cpu time, one or all lwps
- How can I map this value to an actual %CPU usage?

pr_pctmem: % of of system memory used by the process
- What is meant by system memory?
- How can I map this value to an actual %CPU usage?

- For pr_pctcpu and pr_pctmem, the following comment appears in the
  description of the prpsinfo_t structure:

                        /* The following percent numbers are 16-bit binary */
            /* fractions [0 .. 1] with the binary point to the */
            /* right of the high-order bit (one == 0x8000)

        Thanks for any pointers,


(514) 335-3015 ext 244
(514) 335-1614 (fax)
General DataComm
Multimedia Research & Development Center
5490, blvd Thimens, bureau 110
Ville St-Laurent, Quebec
Canada, H4R 2K9

2. IP routing with Quad Enet card

3. Memory usage and prpsinfo

4. Getting a tape drive for Linux PC

5. about struct prpsinfo

6. fmli, face, and this /usr/vmsys directory

7. Structures in structures

8. cachefs: what are it's characteristics?

9. eth0: error fetching interface

10. fetching data form Dialog

11. Failed to fetch large files from Canon A70 via USB: 'Corrupted data'

12. Looking for Fetch

13. fetch mail & POP3