summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--doc/coreutils.texi38
-rw-r--r--src/uptime.c26
3 files changed, 53 insertions, 12 deletions
diff --git a/TODO b/TODO
index c7bb820d2..18371b396 100644
--- a/TODO
+++ b/TODO
@@ -11,7 +11,6 @@ document the following in coreutils.texi:
mktemp
[
pinky
- uptime
Also document the SELinux changes.
Suggestion from Paul Eggert:
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index b47448f5d..f60f9c7fb 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -31,7 +31,6 @@
@c FIXME: the following need documentation
@c * [: (coreutils)[ invocation. File/string tests.
@c * pinky: (coreutils)pinky invocation. FIXME.
-@c * uptime: (coreutils)uptime invocation. FIXME.
@c * mktemp: (coreutils)mktemp invocation. FIXME.
@c * chcon: (coreutils)chcon invocation. FIXME.
@@ -124,6 +123,7 @@
* unexpand: (coreutils)unexpand invocation. Convert spaces to tabs.
* uniq: (coreutils)uniq invocation. Uniquify files.
* unlink: (coreutils)unlink invocation. Removal via unlink(2).
+* uptime: (coreutils)uptime invocation. Print uptime and load.
* users: (coreutils)users invocation. Print current user names.
* vdir: (coreutils)vdir invocation. List directories verbosely.
* wc: (coreutils)wc invocation. Line, word, and byte counts.
@@ -193,7 +193,7 @@ Free Documentation License''.
* File name manipulation:: dirname basename pathchk
* Working context:: pwd stty printenv tty
* User information:: id logname whoami groups users who
-* System context:: date uname hostname hostid
+* System context:: date uname hostname hostid uptime
* Modified command invocation:: chroot env nice nohup su timeout
* Process control:: kill
* Delaying:: sleep
@@ -407,7 +407,8 @@ System context
* date invocation:: Print or set system date and time
* uname invocation:: Print system information
* hostname invocation:: Print or set system name
-* hostid invocation:: Print numeric host identifier.
+* hostid invocation:: Print numeric host identifier
+* uptime invocation:: Print system uptime and load
@command{date}: Print or set system date and time
@@ -12786,6 +12787,7 @@ information.
* uname invocation:: Print system information.
* hostname invocation:: Print or set system name.
* hostid invocation:: Print numeric host identifier.
+* uptime invocation:: Print system uptime and load
@end menu
@@ -13614,6 +13616,36 @@ the case.
@exitstatus
+@node uptime invocation
+@section @command{uptime}: Print system uptime and load
+
+@pindex uptime
+@cindex printing the system uptime and load
+
+@command{uptime} prints the current time, the system's uptime, the
+number of logged-in users and the current load average.
+
+If an argument is specified, it is used as the file to be read
+to discover how many users are logged in. If no argument is
+specified, a system default is used (@command{uptime --help} indicates
+the default setting).
+
+The only options are @option{--help} and @option{--version}.
+@xref{Common options}.
+
+For example, here's what it prints right now on one system I use:
+
+@example
+$ uptime
+ 14:07 up 3:35, 3 users, load average: 1.39, 1.15, 1.04
+@end example
+
+The precise method of calculation of load average varies somewhat
+between systems. Some systems calculate it as the average number of
+runnable processes over the last 1, 5 and 15 minutes, but some systems
+also include processes in the uninterruptible sleep state (that is,
+those processes which are waiting for disk I/O). The Linux kernel
+includes uninterruptible processes.
@node Modified command invocation
@chapter Modified command invocation
diff --git a/src/uptime.c b/src/uptime.c
index 56ad861b1..b35e97a48 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -36,6 +36,7 @@
#include "long-options.h"
#include "quote.h"
#include "readutmp.h"
+#include "fprintftime.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "uptime"
@@ -126,12 +127,10 @@ print_uptime (size_t n, const STRUCT_UTMP *this)
uphours = (uptime - (updays * 86400)) / 3600;
upmins = (uptime - (updays * 86400) - (uphours * 3600)) / 60;
tmn = localtime (&time_now);
+ /* procps' version of uptime also prints the seconds field, but
+ previous versions of coreutils don't. */
if (tmn)
- printf (_(" %2d:%02d%s up "),
- ((tmn->tm_hour % 12) == 0 ? 12 : tmn->tm_hour % 12),
- /* FIXME: use strftime, not am, pm. Uli reports that
- the german translation is meaningless. */
- tmn->tm_min, (tmn->tm_hour < 12 ? _("am") : _("pm")));
+ fprintftime (stdout, _(" %H:%M%P up "), tmn, 0, 0);
else
printf (_(" ??:???? up "));
if (uptime == (time_t) -1)
@@ -197,10 +196,21 @@ usage (int status)
printf (_("\
Print the current time, the length of time the system has been up,\n\
the number of users on the system, and the average number of jobs\n\
-in the run queue over the last 1, 5 and 15 minutes.\n\
+in the run queue over the last 1, 5 and 15 minutes."));
+#ifdef __linux__
+ /* It would be better to introduce a configure test for this,
+ but such a test is hard to write. For the moment then, we
+ have a hack which depends on the preprocessor used at compile
+ time to tell us what the running kernel is. Ugh. */
+ printf(_(" \
+Processes in\n\
+an uninterruptible sleep state also contribute to the load average.\n"));
+#else
+ printf(_("\n"));
+#endif
+ printf (_("\
If FILE is not specified, use %s. %s as FILE is common.\n\
-\n\
-"),
+\n"),
UTMP_FILE, WTMP_FILE);
fputs (HELP_OPTION_DESCRIPTION, stdout);
fputs (VERSION_OPTION_DESCRIPTION, stdout);