times call: user, system, child user, child system

times call: user, system, child user, child system

Post by gaius.petroni » Tue, 25 Dec 2001 13:33:01



This is working.  i have 2 questions regarding the code below:

1. What is the definition of child user and system time as opposed to
the system time of the process itself?  i.e. since it is one (1) long,
is it a total of all children?  Please refer me to documentation if i
missed it in the faqs.

2. as this is similar to the unix times/timex commands, i need to
process argv[].  of course i can process argv[] any way i please, but
is there a standard way to run through these arguments?

code follows

/*      vmtimes.c
 *
 *      2001-12-24
 *
 *      uses the following system call:
 *      long times( struct tms *ptr ) ;
 *      uses the following structure:
 *      struct tms {
 *      time_t tms_utime;   / * user time * /
 *      time_t tms_stime;   / * system time * /
 *      time_t tms_cutime;  / * user time, children * /
 *      time_t tms_cstime;  / * system time, children * /
 *      };
 *
 *      clock ticks per second defined in sys/param.h constant HZ
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/times.h>

main (argc, argv)
        int argc;
        char *argv[]; {
                struct tms tms_local;
                times( &tms_local);
                printf("usr: %d system: %d chld(usr): %d chld(sys): %d\n",
                                tms_local.tms_utime,
                                tms_local.tms_stime,
                                tms_local.tms_cutime,
                                tms_local.tms_cstime);
                exit(0);
        }

 
 
 

times call: user, system, child user, child system

Post by Barry Margoli » Wed, 26 Dec 2001 04:52:32




>This is working.  i have 2 questions regarding the code below:

>1. What is the definition of child user and system time as opposed to
>the system time of the process itself?  i.e. since it is one (1) long,
>is it a total of all children?  Please refer me to documentation if i
>missed it in the faqs.

It's the total of all its children that have exited and been waited for.

The Solaris 2.6 man page says:

     The times of a terminated child process are included in  the
     tms_cutime  and  tms_cstime  elements  of  the  parent  when
     wait(2) or waitpid(2) returns the process ID  of  this  ter-
     minated  child.   If  a child process has not waited for its
     children, their times will not be included in its times.
     ...
     The tms_cutime member is the sum of the  tms_utime  and  the
     tms_cutime of the child processes.

     The tms_cstime member is the sum of the  tms_stime  and  the
     tms_cstime of the child processes.

Quote:>2. as this is similar to the unix times/timex commands, i need to
>process argv[].  of course i can process argv[] any way i please, but
>is there a standard way to run through these arguments?

I don't see why you wouldn't use getopts() to process the arguments like
timex.  Once you've skipped over the options and found the command to time,
fork a child, execute the command using execvp(), and when the process
exits the parent process should report the child data.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

1. Getting a child and child's child process-id

 Why not just have the parent fork twice ??? Saves a lot of trouble ...
--


#  Have you read your Book In Basic Life Education today ? You should !!  #
#  Any views I express are not necessarily those of Brighton Polytechnic  #
###################### "surivorter erutangis a ma I" ######################

2. /var/adm/lastlog

3. Internal Zip Drive on HP Pavilion

4. Catching termination of child process and system() call

5. SCSI: Aborting command due to TIMEOUT

6. fcntl system calls, xview control and child processes !

7. Setting TERM variable..

8. Catching termination of child process and system() call

9. : User/System time from getrusage/times etc.

10. user-time,system-time

11. Strange system time values through *getrusage* system call.