1 /* uptime.c - Tell how long the system has been running.
3 * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
4 * Copyright 2012 Luis Felipe Strano Moraes <lfelipe@profusion.mobi>
5 * Copyright 2013 Jeroen van Rijn <jvrnix@gmail.com>
8 USE_UPTIME(NEWTOY(uptime, NULL, TOYFLAG_USR|TOYFLAG_BIN))
13 depends on TOYBOX_UTMPX
17 Tell how long the system has been running and the system load
18 averages for the past 1, 5 and 15 minutes.
23 void uptime_main(void)
28 unsigned int days, hours, minutes;
32 // Obtain the data we need.
35 now = localtime(&tmptime);
37 // Obtain info about logged on users
39 while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++;
43 xprintf(" %02d:%02d:%02d up ", now->tm_hour, now->tm_min, now->tm_sec);
46 minutes = info.uptime%60;
48 hours = info.uptime%24;
49 days = info.uptime/24;
50 if (days) xprintf("%d day%s, ", days, (days!=1)?"s":"");
51 if (hours) xprintf("%2d:%02d, ", hours, minutes);
52 else printf("%d min, ", minutes);
53 printf(" %d user%s, ", users, (users!=1) ? "s" : "");
54 printf(" load average: %.02f, %.02f, %.02f\n", info.loads[0]/65536.0,
55 info.loads[1]/65536.0, info.loads[2]/65536.0);