diff options
author | Philippe Charnier <charnier@FreeBSD.org> | 2003-02-05 13:18:17 +0000 |
---|---|---|
committer | Philippe Charnier <charnier@FreeBSD.org> | 2003-02-05 13:18:17 +0000 |
commit | eaed5652bf827ccfcdc0abfadec1f17c135fdb8d (patch) | |
tree | e62378a1f63b908b0377bb1fbc3da836b7f1e838 /bin/ps/print.c | |
parent | e869e5070444920bc846b5936bd0d9584eb56ea6 (diff) | |
download | src-eaed5652bf827ccfcdc0abfadec1f17c135fdb8d.tar.gz src-eaed5652bf827ccfcdc0abfadec1f17c135fdb8d.zip |
Display elapsed time (-o etime) using [[dd-]hh:]mm:ss, which according to
Solaris man page is the POSIX way.
Reviewed by: jmallett
Notes
Notes:
svn path=/head/; revision=110391
Diffstat (limited to 'bin/ps/print.c')
-rw-r--r-- | bin/ps/print.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/bin/ps/print.c b/bin/ps/print.c index 6b3489b78590..69d33bac6a16 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -36,6 +36,7 @@ static char sccsid[] = "@(#)print.c 8.6 (Berkeley) 4/16/94"; #endif /* not lint */ #endif + #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -539,14 +540,30 @@ void elapsed(KINFO *k, VARENT *ve) { VAR *v; - time_t secs; + time_t days, hours, mins, secs; char obuff[128]; v = ve->var; secs = now - k->ki_p->ki_start.tv_sec; - (void)snprintf(obuff, sizeof(obuff), "%3ld:%02ld", (long)secs/60, - (long)secs%60); + days = secs/(24*60*60); + secs %= (24*60*60); + hours = secs/(60*60); + secs %= (60*60); + mins = secs/60; + secs %= 60; + if (days != 0) { + (void)snprintf(obuff, sizeof(obuff), "%3ld-%02ld:%02ld:%02ld", + (long)days, (long)hours, (long)mins, (long)secs); + } + else if (hours != 0) { + (void)snprintf(obuff, sizeof(obuff), "%02ld:%02ld:%02ld", + (long)hours, (long)mins, (long)secs); + } + else { + (void)snprintf(obuff, sizeof(obuff), "%02ld:%02ld", + (long)mins, (long)secs); + } (void)printf("%*s", v->width, obuff); } |