Bug#842879: use uptime, not btime, else wrong start times on some systems

2016-11-05 Thread 積丹尼 Dan Jacobson
Yup just like uptime, w.procps etc. don't bother with btime, you can't
lose! (At least on the handful of systems that I have encountered.)



Bug#842879: use uptime, not btime, else wrong start times on some systems

2016-11-05 Thread Craig Small
On Sun, 6 Nov 2016, 10:18 AM 積丹尼 Dan Jacobson  wrote:

> Craig, it turns out ps is using the wrong file in the first place!
> If it used /proc/uptime it would surely never have this problem on any
> system


Thats a big call to say it won't have a problem on any system. The problem
is lots of systems do dumb things to timers. So to change something like
that it will need to be tested a lot first.

Things that suspend come to mind and systems that use stolen time are
another.
Ill try to find where btime was used and why. there may be a good reason
for it.

Thanks for looking into it more.

 - Craig


Bug#842879: use uptime, not btime, else wrong start times on some systems

2016-11-05 Thread 積丹尼 Dan Jacobson
severity 842879 normal
retitle 842879 use uptime, not btime, else wrong start times on some systems
thanks
Craig, it turns out ps is using the wrong file in the first place!
If it used /proc/uptime it would surely never have this problem on any system.

$ perl /tmp/misTime|head
(init):
b Tue Aug  9 06:05:54 2016
u Sun Oct 16 22:34:14 2016
(pickup):
b Mon Aug 29 12:39:39 2016
u Sun Nov  6 05:08:00 2016
(apache2-ps11007):
b Sun Aug 28 23:13:39 2016
u Sat Nov  5 15:42:00 2016

$ uptime
 07:15:40 up 20 days,  8:41,  1 user,  load average: 0.00, 0.00, 0.00
$ cat /tmp/misTime

#!/usr/bin/perl
# Author  : Dan Jacobson -- http://jidanni.org/
# Created On  : Sat Nov  5 18:11:17 2016
# Last Modified On: Sun Nov  6 05:52:38 2016
# Update Count: 71
# Reproduce wrong time effect
use strict;
use warnings FATAL => q(all);
open( my $fh, "<", "/proc/stat" ) or die;
my $btime;
while (<$fh>) {
if (/^btime/) { /\d+/; $btime = $&; last; }
}
close $fh;
open( my $fh1, "<", "/proc/uptime" ) or die;
my $uptime;
while (<$fh1>) {
/[\d.]+/ || die;
$uptime = $&;
}
close $fh1;
@ARGV = glob "/proc/[0-9]*/stat";
while (<>) {
my @F = split;
printf "%s:\n\tb %s\n\tu %s\n", $F[1],
  scalar localtime( $F[21] / 100 + $btime ),
  scalar localtime( $F[21] / 100 + time - $uptime );
}

#I'll also tell the  libproc-processtable-perl guys.