I want to retrieve some process info from /proc directory and my question is the following: is there a standart format for files in /proc/PID?
For example, there is this proc/PID/status file with Name:'\t'ProcName in its first line. Can I meet this file elsewhere with a whitespace instead of \t or smth like that?
I want to retrieve some process info from /proc directory and my question is
Share
First of all, the documentation on
/procin Linux is provided in the Linux sources, inDocumentation/filesystems/proc.txt. That should be the first place you look into if going to work with procfs. Sadly, AFAICS it doesn’t mention the exact record format.The second place to look is
procpssources (that is, the package which providespstool). There you can find:which means that
psrelies on the:\tbeing there. Therefore, you can assume that all current Linux kernels use this format. Moreover, I doubt that minor changes (like replacing the\twith something else) would be considered important enough to break compatibility with the old versions ofpstool.That said, you can usually be more liberal in what you accept. Considering the specific contents of that file, you can assume the colon being field separator, and strip any whitespace following it. If you are using shell script, the regular field separation should suffice.
Lastly, I’d like to make a few points:
statusfile is supposed to be human-readable. Therefore, programs are usually better reading thestatfile instead which is designed to be machine-oriented./procformat.libprocpslibrary which comes withprocpsinstead of reading the files by hand. That way, you avoid re-inventing the wheel and relying on a specific format directly.