Add Book to My BookshelfPurchase This Book Online

Chapter 9 - System Configuration and Resource Limits

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

Resource Utilization Information
Most versions of UNIX provide the times system call, which can be used to find out how much processor time the current process and its children have used:
    #include <sys/times.h>
    #include <limits.h>
    clock_t times(struct tms *buf);
The struct tms structure is defined as:
    struct tms {
        clock_t tms_utime;
        clock_t tms_stime;
        clock_t tms_cutime;
        clock_t tms_cstime;
    };
The information returned describes the calling process and all of its terminated child processes (see Chapter 11, Processes) for which it has executed a wait routine. The specific fields are:
tms_utime
The amount of processor time used while executing instructions in the user space of the calling process
tms_stime
The amount of processor time used by the system on behalf of the calling process (i.e., the amount of time performing system calls)
tms_cutime
The sum of the tms_utime and tms_cutime values for the child process
tms_cstime
The sum of the tms_stime and tms_cstime values for the child process
All times are reported in clock ticks ; the number of clock ticks per second is defined as CLK_TCK in the limits.h include file, or may be obtained with sysconf.
Upon successful completion, times returns the elapsed real time, in clock ticks, from some time in the past (usually system boot time). This point does not change between calls, so two successive calls to times compute the elapsed time between calls. If the call fails, -1 is returned and an error code is placed in  errno.
Porting Notes
On older systems, times reported time in seconds, rather than clock ticks.
BSD-based systems offer a much more comprehensive facility for obtaining process resource consumption information:
    #include <sys/time.h>
    #include <sys/resource.h>
    int getrusage(int who, struct rusage *rusage);
The who parameter may be given as either RUSAGE_SELF or RUSAGE_CHILDREN; the struct rusage structure is defined as follows:
    struct  rusage {
        struct timeval ru_utime;
        struct timeval ru_stime;
        long    ru_maxrss;
        long    ru_ixrss;
        long    ru_idrss;
        long    ru_isrss;
        long    ru_minflt;
        long    ru_majflt;
        long    ru_nswap;
        long    ru_inblock;
        long    ru_oublock;
        long    ru_msgsnd;
        long    ru_msgrcv;
        long    ru_nsignals;
        long    ru_nvcsw;
        long    ru_nivcsw;
    };
The fields contain:
ru_utime
The total amount of time spent executing in user mode, in seconds and microseconds.
ru_stime
The total amount of time spent executing in system mode, in seconds and microseconds.
ru_maxrss
The maximum resident set size (amount of memory used), in pages.
ru_idrss
An “integral” value indicating the amount of memory in use by a process while the process is running. This is the sum of the resident set sizes of the process running when a clock tick occurs. The value is reported in pages times clock ticks.
ru_minflt
The number of minor page faults (faults that do not require physical I/O activity) serviced.
ru_majflt
The number of major page faults (faults that require physical I/O activity) serviced.
ru_nswap
The number of times the process was swapped out of main memory.
ru_inblock
The number of times the filesystem had to perform input when servicing a read request.
ru_outblock
The number of times the filesystem had to perform output when servicing a write request.
ru_msgsnd
The number of messages sent over sockets.
ru_msgrcv
The number of messages received over sockets.
ru_nsignals
The number of signals delivered to the process.
ru_nvcsw
The number of times a context switch resulted due to the process voluntarily giving up the processor before its time slice was completed (usually to wait on the availability of a resource).
ru_nivcsw
The number of times a context switch resulted due to a higher priority process becoming runnable or because the current process used up its time slice.
This information can be obtained in SVR4 through the /proc filesystem, described in Appendix , The /proc Filesystem.
Beginning with Solaris 2.5, getrusage has been restored as a system call in Solaris 2.x.

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