Linux Kernel development Process Management Pavel Sorokin Gyeong

  • Slides: 16
Download presentation
Linux Kernel development Process Management Pavel Sorokin Gyeong. Sang National University 1

Linux Kernel development Process Management Pavel Sorokin Gyeong. Sang National University 1

Objectives What is process? Process Descriptor and Task Structure Process Identification Value Process State

Objectives What is process? Process Descriptor and Task Structure Process Identification Value Process State Process Family Tree Processes and Threads Process Context and Kernel Threads Process creation Process termination 2

Process is a program in execution that include set of resources open files pending

Process is a program in execution that include set of resources open files pending signals internal kernel data processor state address space threads of execution 3

Process Descriptor and the Task Structure Kernel stores list of processes in a circular

Process Descriptor and the Task Structure Kernel stores list of processes in a circular doubly linked list – task list task_struct task_struct Each element of task list is a large data structure task_struct - process descriptor process state process's address space PID pointer to process parent open files 4

Process Descriptor and the Task Structure task structure – thread_info struct created together with

Process Descriptor and the Task Structure task structure – thread_info struct created together with Process Descriptor to makes easier to work whit it in assembly code task element is a pointer to actual process's Task Structure most kernel code works with task structure 5

Process Identification Value process have a unique Process Identification value - PID System identifies

Process Identification Value process have a unique Process Identification value - PID System identifies process by PID System have limitations of available PID, consequently system have limitations of maximum count of processes example of command “ps ax” output: PID TTY 1? 2? 3? 4? 5? 6? 7? 8? 9? 12 ? 13 ? 14 ? 111 ? 149 ? 150 ? 152 ? 153 ? 1554 ? STAT TIME COMMAND Ss 0: 01 init [2] S 0: 00 [migration/0] SN 0: 00 [ksoftirqd/0] S 0: 00 [migration/1] SN 0: 00 [ksoftirqd/1] S< 0: 00 [events/0] S< 0: 00 [events/1] S< 0: 00 [khelper] S< 0: 00 [kthread] S< 0: 00 _ [kblockd/0] S< 0: 00 _ [kblockd/1] S< 0: 00 _ [kacpid] S< 0: 00 _ [kseriod] S 0: 00 _ [pdflush] S< 0: 00 _ [aio/0] S< 0: 00 _ [aio/1] S< 0: 00 _ [khubd] 6

Process State process always stands in some condition Current process's state can be set

Process State process always stands in some condition Current process's state can be set by one of five flags TASK_RUNNING – process is runnable TASK_INTERRUPTIBLE – process is sleeping TASK_UNINTERRUPTIBLE – process do not respond to signals TASK_ZOMBIE – task is terminated TASK_STOPPED – process execution is stops 7

Process State scheduler dispatches task to run TASK_RUNNING (ready but not running) TASK_RUNNING (running)

Process State scheduler dispatches task to run TASK_RUNNING (ready but not running) TASK_RUNNING (running) task is preempted by higher priority task sleeps on wait queue for a specific event occurs TASK_INTERRUPTIBLE or TASK_UNINTERRUPTIBLE (waiting) 8

Process Family Tree All processes are descends of init process, whose PID is 1

Process Family Tree All processes are descends of init process, whose PID is 1 Process can have only one parent – parent element in process’s task_struct Process can have zero or more children – children list element in process’s task_struct 9

Processes and Threads provide multiple flows of execution in within same program in a

Processes and Threads provide multiple flows of execution in within same program in a shared memory address space Threads can share open files and other resources In Linux threads is a standard processes that shares certain resources with other processes Every thread have it’s own unique task_struct and appears to kernel as normal process 10

Process Context and Kernel Threads Process Context Processes executes within program’s address space –

Process Context and Kernel Threads Process Context Processes executes within program’s address space – user-space When process executes a system call or trigger an exception, it enters kernel-space Processes have no other ways to enter kernel-space Kernel Threads Kernel Thread is standard process that exist solely in kernel-space Kernel Threads do not have an address space Kernel Threads can be created only by another kernel thread 11

Process creation Linux creates process through two separating steps Create a child process that

Process creation Linux creates process through two separating steps Create a child process that is a copy of current task – fork() function The new process differs from it’s parent only in PID, PPID and certain resources and statistics When process executes a system call or trigger an exception, it enters kernel-space Processes have no other ways to enter kernel-space Load process into the address space and begin executing – exec() function Kernel Thread is standard process that exist solely in kernel-space Kernel Threads do not have an address space Kernel Threads can be created only by another kernel thread 12

Process creation Copy-on-Write Prevents copying unnecessary data to child process Unnecessary data just shares

Process creation Copy-on-Write Prevents copying unnecessary data to child process Unnecessary data just shares between processes (read only) Data marked as written will be copied to child process 13

Process termination Process terminates in some steps Process ends it’s work or receives a

Process termination Process terminates in some steps Process ends it’s work or receives a signal or exception that it can’t handle Process starts execution of exit() function release address space of process free recourses that process uses send notify to parent process and stands process state to TASK_ZOMBIE call to schedule to start execution of another process When parent process receive note about it’s child termination system remaining memory held by process task_structure and thread_info 14

Process termination Termination of process that have child processes System tries to reparent child

Process termination Termination of process that have child processes System tries to reparent child process to another process in current thread group If fails child process’s parent stands init process 15

Summary Process is very important system abstraction Process have a distinct hierarchy between each

Summary Process is very important system abstraction Process have a distinct hierarchy between each other Processes and Threads are very similar in Linux Creation of processes differs from other OS Hardships of process terminations 16