[pve-devel] applied: [PATCH container] fix #1704: get container uptime with /proc/<pid>/stat
Thomas Lamprecht
t.lamprecht at proxmox.com
Tue Mar 20 15:41:40 CET 2018
applied
On 3/19/18 4:30 PM, Dominik Csapak wrote:
> 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 at proxmox.com>
> ---
> 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};
>
>
More information about the pve-devel
mailing list