home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1928 / uptime.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  814 b   |  38 lines

  1. /*    uptime.c
  2.  *
  3.  *    displays system uptime and boot-time
  4.  *
  5.  *    3-August-1990, Thad Floryan, original release
  6.  *    23-August-1990, Thad Floryan, "fixed" the output format to be conducive
  7.  *            for use with shell scripts
  8.  */
  9.  
  10. #include <sys/types.h>
  11. #include <sys/times.h>
  12.  
  13. main()
  14. {
  15.     extern long time(), times();
  16.     extern char *ctime();
  17.  
  18.     long boottime, uptime;
  19.     long days, hours, minutes, secs;
  20.     struct tms timebuf;
  21.  
  22.     uptime   = times(&timebuf)/60L;
  23.     boottime = time((long *) 0) - uptime;
  24.     days     = uptime / (24L*60L*60L);
  25.     secs     = uptime % (24L*60L*60L);
  26.     hours    = ( secs / (60L*60L)       );
  27.     minutes  = ((secs % (60L*60L)) / 60L);
  28.     secs     = ((secs % (60L*60L)) % 60L);
  29.  
  30.     printf("up %ld day%s %ld:%02ld:%02ld   booted %s",
  31.         days,
  32.         ((days == 1L) ? "" : "s"),
  33.         hours,
  34.         minutes,
  35.         secs,
  36.         ctime(&boottime));
  37. }
  38.