]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/LXC.pm
fix #1704: get container uptime with /proc/<pid>/stat
[pve-container.git] / 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};