From 0d4b6715406be90f1ffa06d162c3b17ea33c64c7 Mon Sep 17 00:00:00 2001 From: Hiten Pandya Date: Mon, 21 Jun 2004 00:47:57 +0000 Subject: [PATCH] Use the kern.boottime sysctl for retrieving the system boot time as a struct timeval. This is used to fix the STARTED column for pure kernel threads. Note, currently, we do not set the start time for pure threads due to safety issues with microtime(9), although this change conditionalizes the thread start time appropriately, so that in the future when pure threads will account their start time, we wouldn't need to change anything in this utility (with regard to the start time, ofcourse). Discussed-with: Matthew Dillon --- bin/ps/extern.h | 3 ++- bin/ps/print.c | 12 ++++++++++-- bin/ps/ps.c | 14 +++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bin/ps/extern.h b/bin/ps/extern.h index f3d7bb65f0..7d09ce6c56 100644 --- a/bin/ps/extern.h +++ b/bin/ps/extern.h @@ -32,7 +32,7 @@ * * @(#)extern.h 8.3 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ps/extern.h,v 1.9 1999/08/27 23:14:50 peter Exp $ - * $DragonFly: src/bin/ps/extern.h,v 1.5 2004/03/19 17:47:49 cpressey Exp $ + * $DragonFly: src/bin/ps/extern.h,v 1.6 2004/06/21 00:47:57 hmp Exp $ */ struct kinfo; @@ -45,6 +45,7 @@ extern int eval, fscale, mempages, nlistread, rawcpu, cflag; extern int sumrusage, termwidth, totwidth; extern VAR var[]; extern VARENT *vhead; +extern struct timeval btime; __BEGIN_DECLS void command (const KINFO *, const VARENT *); diff --git a/bin/ps/print.c b/bin/ps/print.c index c0aaee3989..f9b5d0024d 100644 --- a/bin/ps/print.c +++ b/bin/ps/print.c @@ -32,7 +32,7 @@ * * @(#)print.c 8.6 (Berkeley) 4/16/94 * $FreeBSD: src/bin/ps/print.c,v 1.36.2.4 2002/11/30 13:00:14 tjr Exp $ - * $DragonFly: src/bin/ps/print.c,v 1.11 2004/06/10 22:11:39 dillon Exp $ + * $DragonFly: src/bin/ps/print.c,v 1.12 2004/06/21 00:47:57 hmp Exp $ */ #include @@ -348,7 +348,15 @@ started(const KINFO *k, const VARENT *ve) if (use_ampm < 0) use_ampm = (*nl_langinfo(T_FMT_AMPM) != '\0'); - then = k->ki_u.u_start.tv_sec; + if (KI_THREAD(k)->td_proc != NULL) { + then = k->ki_u.u_start.tv_sec; + } else { + then = KI_THREAD(k)->td_start.tv_sec; + if (then < btime.tv_sec) { + then = btime.tv_sec; + } + } + tp = localtime(&then); if (!now) (void)time(&now); diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 282ca8344e..527dfa457f 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -33,7 +33,7 @@ * @(#) Copyright (c) 1990, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)ps.c 8.4 (Berkeley) 4/2/94 * $FreeBSD: src/bin/ps/ps.c,v 1.30.2.6 2002/07/04 08:30:37 sobomax Exp $ - * $DragonFly: src/bin/ps/ps.c,v 1.7 2004/06/20 22:29:10 hmp Exp $ + * $DragonFly: src/bin/ps/ps.c,v 1.8 2004/06/21 00:47:57 hmp Exp $ */ #include @@ -96,6 +96,9 @@ static void sizevars (void); static void usage (void); static uid_t *getuids(const char *, int *); +struct timeval btime; +static size_t btime_size = sizeof(struct timeval); + static char dfmt[] = "pid tt state time command"; static char jfmt[] = "user pid ppid pgid sess jobc state tt time command"; static char lfmt[] = "uid pid ppid cpu pri nice vsz rss wchan state tt time command"; @@ -322,6 +325,15 @@ main(int argc, char **argv) * and adjusting header widths as appropriate. */ scanvars(); + + /* + * Get boot time + */ + if (sysctlbyname("kern.boottime", &btime, &btime_size, NULL, 0) < 0) { + perror("sysctl: kern.boottime"); + exit(EXIT_FAILURE); + } + /* * get proc list */ -- 2.41.0