Running pxmx 8.3.1.
I have several LXC containers and in one of them, I would like to programmatically determine the start time of a particular process. My approach has been:
- containeruptime = /proc/uptime field 0
- containerstarttime = now() - uptime
- procstartdelta = (/proc/MYPID/stat field 22 - /proc/1/stat field 22
- return containerstarttime+procstartdelta
Except that gives me completely weird values. Narrowing it down, I have found that /proc/PID/stat contains completely bogus process uptime values:
This would mean that there is a process that has a longer uptime than init in that container, which is clearly not possible. What I now wonder is if I set up my LXC containers wrong or something. I don't see any obvious options regarding /proc, and have used defaults otherwise.
Any suggestions appreciated, except:
- reading the procps code. It's convoluted C code that is just very hard to read for me
- exec'ing ps and parsing its output.
I have several LXC containers and in one of them, I would like to programmatically determine the start time of a particular process. My approach has been:
- containeruptime = /proc/uptime field 0
- containerstarttime = now() - uptime
- procstartdelta = (/proc/MYPID/stat field 22 - /proc/1/stat field 22
- return containerstarttime+procstartdelta
Except that gives me completely weird values. Narrowing it down, I have found that /proc/PID/stat contains completely bogus process uptime values:
Code:
$ awk '{print $22}' /proc/{1,119279}/stat
172979854
180038658
$
This would mean that there is a process that has a longer uptime than init in that container, which is clearly not possible. What I now wonder is if I set up my LXC containers wrong or something. I don't see any obvious options regarding /proc, and have used defaults otherwise.
Any suggestions appreciated, except:
- reading the procps code. It's convoluted C code that is just very hard to read for me
- exec'ing ps and parsing its output.