160 likes | 306 Views
Process Management. Shi-Hui Ker OS Lab., NCTU,Taiwan. Data Structure. task[ NR_TASKS ]. …. state. counter. priority. init_task. Interrupts. Fast interrupts Slow interrupts Software interrupts(system calls). Bottom halves.
E N D
Process Management Shi-Hui Ker OS Lab., NCTU,Taiwan
Data Structure task[NR_TASKS] …... state counter priority init_task
Interrupts • Fast interrupts • Slow interrupts • Software interrupts(system calls)
Bottom halves • a list of tasks to be performed that are necessary for the proper execution of things like device drivers, but do not need to be performed when an interrupt for that device is trapped. • void (*bh_base[32])(void); • bh_mask, bh_active • example: kbd_bh
Schedule() • do_bottom_half() • run_task_queue(&tq_scheduler) • Determine the fate of the previous process. • The process with the highest priority is determined. • Store the state of previous task, and restore the state of next task to CPU.
tq_struct task_queue next next next sync sync sync routine routine routine data data data
Creating a Process • do_fork() • To allocate a new task_struct (*p) from memory for the new process. • To allocate a new page for kernel stack. • To find an unused number from the task array. • To clone the task_struct with current process. • New process initialization. • Return process id to calling process(parent).
Process releationship • p_opptr : original parent • p_cptr : youngest child • p_ysptr : younger sibling • p_osptr : older sibling
Process releationship(cont.) parent p_cptr p_pptr p_pptr p_pptr p_osptr p_osptr oldest child youngest child child p_ysptr p_ysptr
Process termination • A process is always terminated by calling the kernel function do_exit. • Done by the system call _exit or by a unintercepted signal.
do_exit() • release the resources claimed by the current process • inform other processes if necessary. • Call schedule() • goto fake_volatile;
Resources release • sem_exit() • if current process was sleeping for a semaphore, remove it from the wait queue. • __exit_mm(current) • flush cache, TLB • mmap, page table
Informing other processes • exit_notify() • forget_original_parent(current) • scan all processes and modifies the process pointers p_optr to init_task if they are pointing at current process. • kill_pg(); • If the current process is leader of a group which includes the suspended processes, the messages SIGHUP and SIGCONT are sent to the group process by calling the function kill_pg().
Informing other processes(cont.) • notify_parent(current,current->exit_signal); • notify_parent(p, p->exit_signal);
wake_up_interruptible() p Wait_queue_head task task_struct next next task task_struct next task task_struct next task task_struct next Null
sys_wait4() • calling process must be halted until a child process terminates. • joins the wait_childexit wait queue in its own task structure. • flag=TASK_INTERRUPTIBLE • pass control to scheduler(call schedlu()) • when a process terminates, it signals this to its parent process via this queue.