Hi Dan,

On Wed, 2 Nov 2016, 11:30 AM 積丹尼 Dan Jacobson <[email protected]> wrote:

ps should have a way to get the process start time from the local
instance of the VPS, not the entire underlying computer.

For real VPS they do because there is a separate instance of the /proc
filesystem.

$ sleep 4& ps -eo pid,cmd,start_time,bsdstart,start,lstart,stime|grep
sleep|grep -v grep
[1] 978
  978 [sleep]                     21:26  21:26 21:26:48 Wed Nov  2
21:26:48 2016 21:26
$ uptime
 21:26:53 up 3 min,  1 user,  load average: 0.66, 0.18, 0.06
[1]+  Done                    sleep 4
$ date
Wednesday 2 November  21:26:57 AEDT 2016

That is on a kvm instance that has a different uptime to the underlying
computer.

Start times are basically get_btime plus the proc_start_time / Hertz
get_btime is from grep btime /proc/stat
proc_start_time is 22nd field in /proc/<PID>/stat
Hertz is usually 100

So, like this:

*$ *sleep 100 &
[1] 10204
*$ *grep btime /proc/stat | cut -f 2 ; cut -f 22 -d' ' /proc/10204/stat
btime 1477391669
69159649
*$ *date -d @`expr 1477391669 + 691596`
Wednesday 2 November  21:41:05 AEDT 2016
*$ *ps -o stime 10204
STIME
21:41


Note I manually divided the processes start time by 100.


So that field is nonsense...

 Actually no, whatever software the VPS uses is using a bad implementation
of /proc.
I suspect that /proc/stat is the culprit here. ps and the rest of the
procps tools just interprets what it finds in /proc, so if /proc is wrong
they will happily show the wrong thing.

This doesn't sound like a real VPS but a container. Sometimes LXC or docker
shells show this sort of odd behaviour. Do you know what virtualisation
they are using there?

 - Craig

Reply via email to