From 80d5611161473542c43267cf442fa1a241296e19 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 19 Mar 2018 16:30:15 +0100 Subject: [PATCH] fix #1704: get container uptime with /proc//stat stat on /proc/ is reset when caches are dropped (e.g. from pveperf) so get the uptime like lxcfs it does, via /proc//stat Signed-off-by: Dominik Csapak --- src/PVE/LXC.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index a107ec2..12310ef 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -127,6 +127,7 @@ sub vmstatus { my $cdtime = gettimeofday; my $uptime = (PVE::ProcFSTools::read_proc_uptime(1))[0]; + my $clock_ticks = POSIX::sysconf(&POSIX::_SC_CLK_TCK); my $unprivileged = {}; @@ -189,8 +190,8 @@ sub vmstatus { next if !$pid; # skip stopped CTs - my $ctime = (stat("/proc/$pid"))[10]; # 10 = ctime - $d->{uptime} = time - $ctime; # the method lxcfs uses + my $proc_pid_stat = PVE::ProcFSTools::read_proc_pid_stat($pid); + $d->{uptime} = int(($uptime - $proc_pid_stat->{starttime}) / $clock_ticks); # the method lxcfs uses my $unpriv = $unprivileged->{$vmid}; -- 2.39.2