> when using 'uptime' in containers (regardless what kind of containers), 
> it shows the uptime of the host system rather than the one of the container.

It _does_ work on vserver but not on lxc (and similar).

'uptime' is just a pretty-printer for /proc/uptime, you'd need to teach the
kernel what a "container" means.  And here's a problem: unlike vserver where
containers are an in-kernel thing, lxc is merely a wrapper for
chroot+cgroups+unshare.  You can mix and match those yourself -- which
raises the question when two processes stop being in the same "container".
When their root filesystem differs?  When they're in different namespaces --
but which namespace?

I think the best approximation is the PID namespace -- ie, defining
containers as "having separate inits".  But when did the current init start?
There _is_ task->real_start_time, ie, field 22 of /proc/1/stat, but it
changes whenever init is exec()ed.  What we'd want is the time when unshare
was called, and I don't think that's stored anywhere.

Thus, unless someone has a better idea, all we can get in modern containers
is "time since init was started/upgraded".


Meow!
-- 
An imaginary friend squared is a real enemy.

Reply via email to