Is there a defined structure for getting each field of this file for a particular process instead of parsing the file?
Asked
Active
Viewed 2.6k times
8
-
1Maybe ```libprocps``` – gavv Sep 18 '15 at 15:36
-
1https://gitlab.com/procps-ng/procps – gavv Sep 18 '15 at 15:54
1 Answers
8
The /proc/pid
pseudo-filesystem was created in order to make access to a ton of kernel data accessible to other programs without being tied to binary structures. while /proc/pid/status
was designed to
Provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format that's easier for humans to parse. Here's an example:
$ cat /proc/$$/status
Name: bash
State: S (sleeping)
Tgid: 3515
Pid: 3515
PPid: 3452
...
This was in contrast to much older mechanisms like stat(2) which required binary structures like
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device ID (if special file) */
...
};
If you want a more machine readable version of /proc/pid/status
you can use the lexically simpler stat
and statm
as described in proc(5)

msw
- 42,753
- 9
- 87
- 112