如何获取 /proc/[pid]/status 的信息

How to get information of /proc/[pid]/status

是否有为特定进程获取此文件的每个字段而不是解析文件的定义结构?

/proc/pid 伪文件系统的创建是为了让其他程序可以访问大量内核数据,而无需绑定到二进制结构。而 /proc/pid/status 旨在

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
...

这与 stat(2) 等更旧的机制形成对比,后者需要像

这样的二进制结构
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) */
    ...
};

如果您想要机器可读性更好的 /proc/pid/status 版本,您可以使用词法更简单的 statstatm,如 proc(5)

中所述