运行统计信息

  1. u64 utime;//用户态消耗的CPU时间
  2. u64 stime;//内核态消耗的CPU时间
  3. unsigned long nvcsw;//自愿(voluntary)上下文切换计数
  4. unsigned long nivcsw;//非自愿(involuntary)上下文切换计数
  5. u64 start_time;//进程启动时间,不包含睡眠时间
  6. u64 real_start_time;//进程启动时间,包含睡眠时间

进程亲缘关系

用树表示进程关系:

  1. struct task_struct __rcu *real_parent; /* real parent process */
  2. struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
  3. struct list_head children; /* list of my children */
  4. struct list_head sibling; /* linkage in my parent's children list */
  • parent 指向其父进程。当它终止时,必须向它的父进程发送信号。
  • children 表示链表的头部。链表中的所有元素都是它的子进程。
  • sibling 用于把当前进程插入到兄弟链表中。

image.png

进程权限

  1. /* Objective and real subjective task credentials (COW): */
  2. const struct cred __rcu *real_cred;
  3. /* Effective (overridable) subjective task credentials (COW): */
  4. const struct cred __rcu *cred;

所谓的权限,就是我能操纵谁,谁能操纵我。

  • “谁能操作我”,很显然,这个时候我就是被操作的对象,就是 Objective,那个想操作我的就是 Subjective。
  • “我能操作谁”,这个时候我就是 Subjective,那个要被我操作的就是 Objectvie。
  • real_cred 就是说明谁能操作我这个进程
  • cred 就是说明我这个进程能够操作谁。

cred 的定义:

  1. struct cred {
  2. ......
  3. kuid_t uid; /* real UID of the task */
  4. kgid_t gid; /* real GID of the task */
  5. kuid_t suid; /* saved UID of the task */
  6. kgid_t sgid; /* saved GID of the task */
  7. kuid_t euid; /* effective UID of the task */
  8. kgid_t egid; /* effective GID of the task */
  9. kuid_t fsuid; /* UID for VFS ops */
  10. kgid_t fsgid; /* GID for VFS ops */
  11. ......
  12. kernel_cap_t cap_inheritable; /* caps our children can inherit */
  13. kernel_cap_t cap_permitted; /* caps we're permitted */
  14. kernel_cap_t cap_effective; /* caps we can actually use */
  15. kernel_cap_t cap_bset; /* capability bounding set */
  16. kernel_cap_t cap_ambient; /* Ambient capability set */
  17. ......
  18. } __randomize_layout;
  • 第一个是 uid 和 gid,注释是 real user/group id。一般情况下,谁启动的进程,就是谁的 ID。但是权限审核的时候,往往不比较这两个,也就是说不大起作用。
  • 第二个是 euid 和 egid,注释是 effective user/group id。一看这个名字,就知道这个是起“作用”的。当这个进程要操作消息队列、共享内存、信号量等对象的时候,其实就是在比较这个用户和组是否有权限。
  • 第三个是 fsuid 和 fsgid,也就是 filesystem user/group id。这个是对文件操作会审核的权限。

一般说来,fsuid、euid,和 uid 是一样的,fsgid、egid,和 gid 也是一样的。因为谁启动的进程,就应该审核启动的用户到底有没有这个权限。

Linux 中的权限控制

  • 用户/用户组
  • capabilities (更细粒度的权限控制)

内存管理

  1. struct mm_struct *mm;
  2. struct mm_struct *active_mm;

文件与文件系统

  1. /* Filesystem information: */
  2. struct fs_struct *fs;
  3. /* Open file information: */
  4. struct files_struct *files;

总结

image.png