home *** CD-ROM | disk | FTP | other *** search
- /* uptime.c
- *
- * displays system uptime and boot-time
- *
- * 3-August-1990, Thad Floryan, original release
- * 23-August-1990, Thad Floryan, "fixed" the output format to be conducive
- * for use with shell scripts
- */
-
- #include <sys/types.h>
- #include <sys/times.h>
-
- main()
- {
- extern long time(), times();
- extern char *ctime();
-
- long boottime, uptime;
- long days, hours, minutes, secs;
- struct tms timebuf;
-
- uptime = times(&timebuf)/60L;
- boottime = time((long *) 0) - uptime;
- days = uptime / (24L*60L*60L);
- secs = uptime % (24L*60L*60L);
- hours = ( secs / (60L*60L) );
- minutes = ((secs % (60L*60L)) / 60L);
- secs = ((secs % (60L*60L)) % 60L);
-
- printf("up %ld day%s %ld:%02ld:%02ld booted %s",
- days,
- ((days == 1L) ? "" : "s"),
- hours,
- minutes,
- secs,
- ctime(&boottime));
- }
-