]> git.proxmox.com Git - pve-container.git/commitdiff
fix #1704: get container uptime with /proc/<pid>/stat
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 19 Mar 2018 15:30:15 +0000 (16:30 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Mar 2018 14:32:18 +0000 (15:32 +0100)
stat on /proc/<pid> is reset when caches are dropped (e.g. from pveperf)
so get the uptime like lxcfs it does, via /proc/<pid>/stat

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/LXC.pm

index a107ec204b00c2b761810921c6550adad06466cb..12310efaccbf4cd0221630c717ad5da12426d79d 100644 (file)
@@ -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};