The process list | |||||||||
init_task | //i386/kernel/init_task.c | ||||||||
struct task_struct init_task = INIT_TASK(init_task); | |||||||||
REMOVE_LINKS | include/linux/sched.h | ||||||||
SET_LINKS | |||||||||
#define REMOVE_LINKS(p) do { | / | ||||||||
if (thread_group_leader(p)) | / | ||||||||
list_del_init(&(p)->tasks); | / | ||||||||
remove_parent(p); | / | ||||||||
} while (0) | |||||||||
#define SET_LINKS(p) do { | / | ||||||||
if (thread_group_leader(p)) | / | ||||||||
list_add_tail(&(p)->tasks,&init_task.tasks); | / | ||||||||
add_parent(p, (p)->parent); | / | ||||||||
} while (0) | |||||||||
for_each_process | |||||||||
#define for_each_process(p) / | |||||||||
for (p = &init_task ; (p = next_task(p)) != &init_task ; ) | |||||||||
The lists of TASK_RUNNING processes | |||||||||
run_list of task_struct | |||||||||
array of task_struct | |||||||||
Relationships Among Processes | |||||||||
real_parent of task_struct | |||||||||
parent of task_struct | |||||||||
children of task_struct | |||||||||
sibling of task_struct | |||||||||
group_leader of task_struct | |||||||||
tgid | |||||||||
: | |||||||||
The pidhash table and chained lists | |||||||||
four hash tables | |||||||||
because the process descriptor includes fields that represent different types of PID | |||||||||
How Processes Are Organized | |||||||||
TASK_STOPPED, EXIT_ZOMBIE, or EXIT_DEAD state are not linked | |||||||||
TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE state are | |||||||||
subdivided into many classes, each of which corresponds to a specific event | |||||||||
wait_queue_head_t | //include/linux/wait.h | ||||||||
struct _ _wait_queue_head { | |||||||||
spinlock_t lock; | |||||||||
struct list_head task_list; | |||||||||
}; | |||||||||
Element | |||||||||
struct __wait_queue { | |||||||||
unsigned int flags; | |||||||||
struct task_struct * task; | |||||||||
wait_queue_func_t func; | |||||||||
struct list_head task_list; | |||||||||
}; | |||||||||
我就像内核中等待队列中的一个要素。处在睡眠中,在等待某个事件的出现,把我唤醒。 | |||||||||
但是就算这个事件出现了,被唤醒的也不一定是我,因为我不一定处在队列的前头 | |||||||||
exclusive processes | flags == 1 | 排他 | |||||||
exclusive processes | flags == 0 | 非排他 | |||||||
Handling wait queues | |||||||||
DECLARE_WAIT_QUEUE_HEAD(name) | |||||||||
init_waitqueue_head( ) | |||||||||
init_waitqueue_entry(q,p ) | |||||||||
default_wake_function( ) | |||||||||
: | |||||||||
void sleep_on(wait_queue_head_t *q) | //kernel/sched.c | ||||||||
void interruptible_sleep_on(wait_queue_head_t *q) | |||||||||
long interruptible_sleep_on_timeout(wait_queue_head_t *q, long timeout) | |||||||||
long sleep_on_timeout(wait_queue_head_t *q, long timeout) | |||||||||
//kernel/fork.c | |||||||||
void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state) | |||||||||
prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state) | |||||||||
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait) | |||||||||
wake_up | |||||||||
Process Resource Limits | //include/linux/resource.h | ||||||||
struct rlimit { | |||||||||
unsigned long | rlim_cur; | ||||||||
unsigned long | rlim_max; | ||||||||
}; | |||||||||
RLIM_INFINITY (0xffffffff) | |||||||||
/* | |||||||||
* Resource limits | |||||||||
*/ | |||||||||
#define RLIMIT_CPU | 0 | /* CPU time in ms */ | |||||||
#define RLIMIT_FSIZE | 1 | /* Maximum filesize */ | |||||||
#define RLIMIT_DATA | 2 | /* max data size */ | |||||||
#define RLIMIT_STACK | 3 | /* max stack size */ | |||||||
#define RLIMIT_CORE | 4 | /* max core file size */ | |||||||
#define RLIMIT_RSS | 5 | /* max resident set size */ | |||||||
#define RLIMIT_NPROC | 6 | /* max number of processes */ | |||||||
#define RLIMIT_NOFILE | 7 | /* max number of open files */ | |||||||
#define RLIMIT_MEMLOCK | 8 | /* max locked-in-memory address space */ | |||||||
#define RLIMIT_AS | 9 | /* address space limit */ | |||||||
#define RLIMIT_LOCKS | 10 | /* maximum file locks held */ | |||||||
#define RLIM_NLIMITS | 11 | ||||||||