home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / time14.zip / time-1.4 / wait3.c < prev   
C/C++ Source or Header  |  1992-07-03  |  1KB  |  57 lines

  1. /* Partial wait3 emulation for non-BSD systems.
  2.    Written by Franc,ois Pinard.  */
  3.  
  4. #include <sys/types.h>
  5. #include <sys/times.h>
  6. #include <sys/param.h>
  7.  
  8. #ifdef HAVE_SYS_TIME_H
  9. #include <sys/time.h>
  10. #else
  11. #include "timeval.h"
  12. #endif
  13.  
  14. #ifdef HAVE_SYS_RESOURCE_H
  15. #include <sys/resource.h>
  16. #else
  17. #include "rusage.h"
  18. #endif
  19.  
  20. /* Must be used with the below gettimeofday emulation.  */
  21.  
  22. int
  23. wait3 (status, options, rusage)
  24.      int *status;
  25.      int options;
  26.      struct rusage *rusage;
  27. {
  28.   struct tms tms;
  29.   int pid;
  30.  
  31.   pid = wait (status);
  32.   memset (rusage, 0, sizeof (struct rusage));
  33.  
  34.   times (&tms);
  35.   rusage->ru_utime.tv_sec = tms.tms_cutime / HZ;
  36.   rusage->ru_utime.tv_usec = tms.tms_cutime % HZ * (1000000 / HZ);
  37.   rusage->ru_stime.tv_sec = tms.tms_cstime / HZ;
  38.   rusage->ru_stime.tv_usec = tms.tms_cstime % HZ * (1000000 / HZ);
  39.  
  40.   return pid;
  41. }
  42.  
  43. /* This version is only useful with the above wait3.  */
  44.  
  45. int
  46. gettimeofday (tp, tz)
  47.      struct timeval *tp;
  48.      struct timezone *tz;
  49. {
  50.   int value;
  51.   struct tms tms;
  52.  
  53.   value = times (&tms);
  54.   tp->tv_sec = value / HZ;
  55.   tp->tv_usec = value % HZ * (1000000 / HZ);
  56. }
  57.