I have a few questions about the process information avaiable in GNU/Linux via procfs. This was originally prompted by a desire to extract vmPeak, vmSize, vmRSS & vmHWM from within an application.
I started with the working assumption that
/proc/<pid>/status
is a human readable version of /proc/<pid>/stat
which is machine readable as per the kernel.org commentry:
stat - Process status
status - Process status in human readable form
I realised this was not quite correct when I noticed vmPeak is only available from /proc/pid/status
.
It seems that /proc/pid/status
actually combines values from several places and adds some of its own.
Given we have /proc/pid/status
if there any reason to use /proc/pid/stat
at all? What needs it?
Why have two APIs? Could /proc/pid/stat
be deprecated or does it have a use?
stat
is not equivalent. It has less fields on offer. It is only slightly easier to parse (with a subtle bug if you do it naively). Any programs using stat could easily switch to using status instead. How many would really break?
I have just written parsers for both (though ultimately I binned the one for stat as the API is less useful). For machine readable there is not much in it. In fact the parser for 'status' ends up being more elegant as you can read it directly into any kind of key value store you like. Status seems easier to parse from any language and extensible.
How many programs actually depend on 'stat' rather than 'status'? Do any of them really need the trivial parsing speed up that this might offer?
Now I understand that stat couldn't be removed for years because of backwards compatibility but you could say 'this is now deprecated' unless there is a very good reason to keep it (which would be one possible answer to my question).
If performance is an issue surely converting this kernel information to text and back via a virtual file system is less performant than a library call would be.
It may be obnoxious to keep adding new APIs as this answer suggests but given that a great deal of this is stable why isn't there C library API like for example, sysinfo?