Linux2.6进程的状态 00163: 00164: Task state bitmask.NOTE!These bits are also 00165: 米 encoded in fs/proc/array.c:get_task_state(). 00166: 米 00167: We have two separate sets of flags:task->state 00168: is about runnability,while task->exit_state are 00169: about the task exiting.Confusing,but this way 00170: modifying one set can't modify the other one by 00171: mistake. 00172: */ include/linux/sched.h 00173: #define TASK RUNNING 0 00174: #define TASK INTERRUPTIBLE 1 00175:#define TASK_UNINTERRUPTIBLE 2 00176:#defineTASK_STOPPED 4 00177: #define TASK_TRACED 8 00178:/in tsk->exit state 00179:#define EXIT ZOMBIE 16d 00180:#define EXIT DEAD 32 简单过一下,与状态相关的一些宏 00181: /in tsk->state again 米 1)组合状态 00182: #define TASK DEAD 64 2)状态判断 00183:#define TASK WAKEKILL 128 3)状态设置 嵌入式系统实验室 2023/7/14 Linux操作系统分析 8/65 EMBEDDED SYSTEM LABORATORY 5uE料DUAN0 ITUTE FOR AOVANCED5 FUOY OF U百TC
2023/7/14 Linux操作系统分析 8/65 Linux2.6进程的状态 简单过一下,与状态相关的一些宏 1)组合状态 2)状态判断 3)状态设置 include/linux/sched.h
进程状态转换图 一个既在的 EXIT ZOMBIE 进程调用fork 或者 来创建一个 EXIT_DEAD 或者 新进程 TASK_DEAD 调度器选择一个task: schedule()call Task context switch 进程调用do_exit( forks 终止执行 TASK RUNNING TASK RUNNING 〔就绪,但是没 (正在运行) 有在运行) 进程被高优先级的 进程抢占 进程睡眠在等待特定事件 或是资源的等待队列上 TASK INTERRUP TIBLE 事件发生或资源可用,进 ox 程被唤醒并被放到运行 TASK UNINTERRUP TIBLE 队列上 (等待中)
2023/7/14 Linux操作系统分析 9/65 进程状态转换图 EXIT_ZOMBIE 或者 EXIT_DEAD 或者 TASK_DEAD
标识一个进程 。使用进程描述符地址 >进程和进程描述符之间有非常严格的一一对应关系, 使得用32位进程描述符地址标识进程非常方便 使用PID(Process ID,PID) >每个进程的PID都存放在进程描述符的pid域中 ersity of Science and technolooy 嵌入式系统实验室 2023/7/14 Linux操作系统分析 10/65 EMBEDDED SYSTEM LABORATORY 5uE料DUN0 ITUTE FOR AOVANCED5 FUOY OF U百TD
2023/7/14 Linux操作系统分析 10/65 标识一个进程 ❖使用进程描述符地址 ➢进程和进程描述符之间有非常严格的一一对应关系, 使得用32位进程描述符地址标识进程非常方便 ❖使用PID (Process ID,PID) ➢每个进程的PID都存放在进程描述符的pid域中
进程的PID 冬进程的pid字段 01095: pid_t pid; 01096: pid_t tgid; 00024: typedefkernel_pid_t pid_t; include/linux/types.h 00014: typedef int kernel_pid_t; include/asm-XXX/posix_typesYYY.h Pid最大值,参见kernel/pid.c 00045: int pid_max PID MAX DEFAULT; 顺序使用 && 00024: 循环使用 00025: This controls the default maximum pid allocated to a process 00026: */ include/linux/threads.h 00027: #define PID_MAX_DEFAULT (CONFIG_BASE_SMALL 0x1000 0x8000) 嵌入式系统实验室 2023/7/14 Linux操作系统分析 11/65 EMBEDDED SYSTEM LABORATORY SUZHOU INSTITUTE FON ADVANCED STUDY OF USTC
2023/7/14 Linux操作系统分析 11/65 进程的PID ❖进程的pid字段 Pid最大值,参见kernel/pid.c 顺序使用 && 循环使用 include/linux/types.h include/asm-XXX/posix_typesYYY.h include/linux/threads.h
stuct pid 阅读include/linux/pid.h中 >What is struct pid?” struct upid /Try to keep pid chain in the same cacheline as nr for find pid int nr; struct pid_namespace *ns; struct hlist node pid chain; }; struct pid atomic_t count; /lists of tasks that use this pid * struct hlist_head tasks [PIDTYPE_MAX]; struct rcu head rcu; unsigned int level; struct upid numbers[1]; static inline pid_t pid_nr(struct pid *pid) Cience an pid t nr =0; if (pid) nr pid->numbers[0].nr; 2023/7/14 Linux操作系统分析 return nr;
2023/7/14 Linux操作系统分析 12/65 stuct pid ❖阅读include/linux/pid.h中 ➢“What is struct pid?