Add Book to My BookshelfPurchase This Book Online

Appendix C - The /proc Filesystem

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Obtaining Process Status
The PIOCSTATUS code returns status information for the open process, and places it into a structure of type prstatus_t, which looks like this in Solaris 2.x (it's slightly different in IRIX 5.x):
    typedef struct prstatus {
      long        pr_flags;       /* Flags (see below)                        */
      short       pr_why;         /* Reason for process stop (if stopped)     */
      short       pr_what;        /* More detailed reason                     */
      siginfo_t pr_info;          /* Info associated with signal or fault     */
      short       pr_cursig;      /* Current signal                           */
      u_short     pr_nlwp;        /* Number of lwps in the process            */
      sigset_t pr_sigpend;        /* Set of signals pending to the process    */
      sigset_t pr_sighold;        /* Set of signals held (blocked) by the lwp */
      struct      sigaltstack pr_altstack; /* Alternate signal stack info     */
      struct      sigaction pr_action; /* Signal action for current signal    */
      pid_t       pr_pid;         /* Process id                               */
      pid_t       pr_ppid;        /* Parent process id                        */
      pid_t       pr_pgrp;        /* Process group id                         */
      pid_t       pr_sid;         /* Session id                               */
      timestruc_t pr_utime;       /* Process user cpu time                    */
      timestruc_t pr_stime;       /* Process system cpu time                  */
      timestruc_t pr_cutime;      /* Sum of children's user times             */
      timestruc_t pr_cstime;      /* Sum of children's system times           */
      char        pr_clname[PRCLSZ]; /* Scheduling class name                 */
      short       pr_syscall;     /* System call number (if in syscall)       */
      short       pr_nsysarg;     /* Number of arguments to this syscall      */
      long        pr_sysarg[PRSYSARGS]; /* Arguments to this syscall          */
      id_t        pr_who;         /* Specific lwp identifier                  */
      sigset_t pr_lwppend;        /* Set of signals pending to the lwp        */
      struct ucontext *pr_oldcontext; /* Address of previous ucontext         */
      caddr_t     pr_brkbase;     /* Address of the process heap              */
      u_long      pr_brksize;     /* Size of the process heap, in bytes       */
      caddr_t     pr_stkbase;     /* Address of the process stack             */
      u_long      pr_stksize;     /* Size of the process stack, in bytes      */
      short       pr_processor;   /* processor which last ran this LWP        */
      short       pr_bind;        /* processor LWP bound to or PBIND_NONE     */
      long        pr_instr;       /* Current instruction                      */
      prgregset_t pr_reg;         /* General registers                        */
    } prstatus_t;
Some of the more interesting fields of this structure are:
pr_pid
The process' process ID.
pr_ppid
The process' parent process ID.
pr_pgrp
The process' process-group ID.
pr_sid
The process' session ID.
pr_utime
The amount of user time the process has accumulated.
User time is accumulated when the CPU is executing the process' program code. The timestruc_t structure is similar to a struct timeval, but contains elements for seconds and nanoseconds (as opposed to seconds and microseconds). The elements of the structure are tv_sec and tv_nsec, respectively.
pr_stime
The amount of system time the process has accumulated.
System time is accumulated when the CPU is executing operating system kernel code on behalf of the process; in other words, this is the amount of time the process has spent doing system calls.
pr_cutime
The sum of the user time accumulated by all of the process' children.
This number includes only those processes that have exited and been waited on.
pr_cstime
The sum of the system time accumulated by all of the process' children.
This number includes only those processes that have exited and been waited on.
pr_brksize
The size in bytes of the process' break (the amount of memory that has been allocated via the brk and sbrk system calls).
Generally, this number gives the amount of memory the process has dynamically allocated using malloc and its associated routines.
pr_stksize
The size in bytes of the process' stack.
The stack grows automatically as more space is needed.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback