1

I would like to programmatically acquire the memory usage of the current running process (from within that process). The following SO post explains in detail how this can be achieved. However, what is suggested in that post is to acquire these values from proc pseudo filesystem. Since I want this to work properly also if the process is running in a container (not necessarily a docker container), I am not sure will this approach yield correct results.

The reason for my concerns are various articles (Why top and free inside container show wrong memory, Memory inside Linux containers) that explain how information in proc is not aware of cgroups and memory limits imposed on the container. What I want to acquire is the memory used by my process, not total/available memory, so since my container process is in reality running on the host OS, my assumption is that values VmSize, VmRss and VmPeak from /proc/self/status will still show correct values.

So my questions are:

  • Is my assumption that /proc/self/status can still reliably be used correct, or am I overlooking something?
  • If using /proc/self/status is not reliable, is there some better way (maybe the corresponding cgroup of the process holds this information)?
Marko Popovic
  • 3,999
  • 3
  • 22
  • 37

0 Answers0