Does /proc/[pid]/status always use kB?

Particularly, does proc always list the VmRSS value in kB? I can’t find a solid answer on the documentation, although it appears that it sticks to one unit.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Yes, it’s always in kB. KiB (1024-bytes, not 1000) to be exact.

At least in Linux 4.0 (and this code has been largely unchanged since at least April 2005—that’s when Linus switched to git, and I don’t care to check back further) that output comes from task_mem in fs/proc/task_mmu.c. Excerpting a few lines:

seq_printf(m,
    "VmPeak:\t%8lu kB\n"
    "VmSize:\t%8lu kB\n"
    "VmLck:\t%8lu kB\n"
    "VmPin:\t%8lu kB\n"
    "VmHWM:\t%8lu kB\n"
    "VmRSS:\t%8lu kB\n"
    "VmData:\t%8lu kB\n"
    "VmStk:\t%8lu kB\n"
    "VmExe:\t%8lu kB\n"
    "VmLib:\t%8lu kB\n"
    "VmPTE:\t%8lu kB\n"
    "VmPMD:\t%8lu kB\n"
    "VmSwap:\t%8lu kB\n",
    hiwater_vm << (PAGE_SHIFT-10),
    ⋮
);

Not sure if you can read C, but that “kB” is hardcoded there. There is no logic to output any other unit.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply