diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2019-10-22 21:19:23 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2019-10-22 21:19:23 +0000 |
commit | 54b9dd9cf5831fb91eebb37310440d46cb39e2ee (patch) | |
tree | c94408078c4bb7fad06aed10f985438935fee5f1 /sys/kern/kern_acct.c | |
parent | 23155841bdcad30e4e0715e943a52d6a5ec5c0e3 (diff) |
struct proc: change ps_start from utc time to uptime
Allows us to determine how long a process has been running, even if the
UTC clock jumps.
With help from bluhm@ and millert@, who squashed several bugs.
ok bluhm@ millert@
Diffstat (limited to 'sys/kern/kern_acct.c')
-rw-r--r-- | sys/kern/kern_acct.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 6d85501d26a..f46ebf61d88 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_acct.c,v 1.41 2019/10/06 16:24:14 beck Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.42 2019/10/22 21:19:22 cheloha Exp $ */ /* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- @@ -171,7 +171,7 @@ acct_process(struct proc *p) struct acct acct; struct process *pr = p->p_p; struct rusage *r; - struct timespec ut, st, tmp; + struct timespec booted, elapsed, realstart, st, tmp, uptime, ut; int t; struct vnode *vp; int error = 0; @@ -203,10 +203,12 @@ acct_process(struct proc *p) acct.ac_stime = encode_comp_t(st.tv_sec, st.tv_nsec); /* (3) The elapsed time the command ran (and its starting time) */ - acct.ac_btime = pr->ps_start.tv_sec; - getnanotime(&tmp); - timespecsub(&tmp, &pr->ps_start, &tmp); - acct.ac_etime = encode_comp_t(tmp.tv_sec, tmp.tv_nsec); + nanouptime(&uptime); + nanoboottime(&booted); + timespecadd(&booted, &pr->ps_start, &realstart); + acct.ac_btime = realstart.tv_sec; + timespecsub(&uptime, &pr->ps_start, &elapsed); + acct.ac_etime = encode_comp_t(elapsed.tv_sec, elapsed.tv_nsec); /* (4) The average amount of memory used */ r = &p->p_ru; |