Mercurial > hg > toybox
view toys/other/uptime.c @ 818:264b9da809df
Simplify license text, as mentioned on the mailing list.
Reasoning: it was never my intent to require anybody to copy license
text into another project if they cut and pasted something out of
toybox. The "permission for any purpose" is as close to public domain
as you can get in our current screwed up legal system without making
people uncomfortable the _other_ way. (Besides, my initial reading of
that was "all copies of the source code" but that's not what it says,
and somebody pointed out that Android has "show license text" options
because paranoid lawyers think that sort of thing applies to the BINARY
version, which is nuts.)
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 14 Mar 2013 09:02:37 -0500 |
parents | 786841fdb1e0 |
children | 960462460639 |
line wrap: on
line source
/* uptime.c - Tell how long the system has been running. * * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com> USE_UPTIME(NEWTOY(uptime, NULL, TOYFLAG_USR|TOYFLAG_BIN)) config UPTIME bool "uptime" default y help usage: uptime Tell how long the system has been running and the system load averages for the past 1, 5 and 15 minutes. */ #include "toys.h" void uptime_main(void) { struct sysinfo info; time_t tmptime; struct tm * now; unsigned int days, hours, minutes; // Obtain the data we need. sysinfo(&info); time(&tmptime); now = localtime(&tmptime); // Time xprintf(" %02d:%02d:%02d up ", now->tm_hour, now->tm_min, now->tm_sec); // Uptime info.uptime /= 60; minutes = info.uptime%60; info.uptime /= 60; hours = info.uptime%24; days = info.uptime/24; if (days) xprintf("%d day%s, ", days, (days!=1)?"s":""); if (hours) xprintf("%2d:%02d, ", hours, minutes); else printf("%d min, ", minutes); printf(" load average: %.02f %.02f %.02f\n", info.loads[0]/65536.0, info.loads[1]/65536.0, info.loads[2]/65536.0); }