In order to track my program's memory usage, I wrote a script that records /proc/pid/status every 0.01 seconds and extracted memory usage from it. I checked most of the records and everything was fine, but data related to memory usage disappeared in the last few records when the program was about to terminate (about in 0.05 seconds).
Here's the last record but 5, where everything was fine:
Name: problem
Umask: 0022
State: R (running)
Tgid: 1910
Ngid: 0
Pid: 1910
PPid: 1909
TracerPid: 0
Uid: 1001 1001 1001 1001
Gid: 1001 1001 1001 1001
FDSize: 64
Groups: 1001
NStgid: 1910
NSpid: 1910
NSpgid: 1909
NSsid: 1909
VmPeak: 3124988 kB
VmSize: 3124988 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 3122016 kB
VmRSS: 3122016 kB
RssAnon: 3118940 kB
RssFile: 3076 kB
RssShmem: 0 kB
VmData: 3119124 kB
VmStk: 132 kB
VmExe: 8 kB
VmLib: 3104 kB
VmPTE: 6156 kB
VmSwap: 0 kB
HugetlbPages: 0 kB
CoreDumping: 0
Threads: 1
SigQ: 0/62912
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Speculation_Store_Bypass: vulnerable
Cpus_allowed: fff
Cpus_allowed_list: 0-11
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 0
nonvoluntary_ctxt_switches: 5
Here's the last record but 4, where data related to memory usage disappeared:
Name: problem
Umask: 0022
State: R (running)
Tgid: 1910
Ngid: 0
Pid: 1910
PPid: 1909
TracerPid: 0
Uid: 1001 1001 1001 1001
Gid: 1001 1001 1001 1001
FDSize: 64
Groups: 1001
NStgid: 1910
NSpid: 1910
NSpgid: 1909
NSsid: 1909
Threads: 1
SigQ: 0/62912
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000000000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
Seccomp: 0
Speculation_Store_Bypass: vulnerable
Cpus_allowed: fff
Cpus_allowed_list: 0-11
Mems_allowed: 1
Mems_allowed_list: 0
voluntary_ctxt_switches: 0
nonvoluntary_ctxt_switches: 5
I wonder why this is happening, and how I could collect memory usage data when my program is about to terminate?