220 likes | 349 Views
Operating Systems - process. Seehwan Yoo Mse.cis.dku. Review. Computer systems organization (hardware) Main components CPU: instruction execution Memory: store data/instruction (program) I/O devices: interact with outer world Bus: an inter-connect across hw Address Data Control.
E N D
OperatingSystems- process Seehwan Yoo Mse.cis.dku
Review • Computer systems organization (hardware) • Main components • CPU: instruction execution • Memory: store data/instruction (program) • I/O devices: interact with outer world • Bus: an inter-connect across hw • Address • Data • Control • Input/output device operation • Accessing registers • Mem-mapped I/O • I/O-mapped I/O • Event checking • Interrupt: notify of event to cpu • Polling: cpu manually checks status • DMA • Bulk data transfer • Avoid cpuintervention
Review • Operating systems structure • Kernel • User programs • Dual-mode OS: protection support by hw • User mode • Kernel mode • System call • OS service call • Across protection boundary (from user to kernel) • No API, but ABI • Multi-user systems • Multi-programming: running multiple user applications
Process & execution context • Program in execution • Abstraction for processor • Every process has its own execution ‘context’ • CPU register values • Incl. PC, SP, A0, V0, … • Address space (memory) • State • Open files
Program vs. process Program Process Loaded in memory Has execution context PC, SP, live registers, open files, memory contents • Stored in disk • No active execution context • No PC, no SP, no run-time data
Process Memory or address space • Address • of your home? • Address is given to memory location • LW/SW (load/store) data to some memory location • Address space • Set of address {from begin to end} • {0, …, 4G} (for 32bit machine) • Process has its own address space • Every process runs only within his own address space • Will be addressed, later (in virtual memory chapter)
Memory layout • Process should have memory region for • Text: program code • Data • Stack • Heap • And kernel • All above within 0~4G address space • Written in your program
Time-sharing system • Multiple processes run concurrently • assumption: 1 CPU system • OS makes illusion • Feels like each process has its own CPU • And all processes run at the same time • Conceptually, • Make process A run, then stop • Make process B run, then stop • …
Time-sharing system’s implementation • Timer runs • Generates timer interrupts periodically • 1s/ 10ms/ 1ms • Like heartbeat • When CPU gets timer interrupt, • Account CPU usage of the process • Time quantum (or time slice): max. time given to a process without interruption • When a process consumes all its quantum, change the runningprocess • Scheduler determines which process to run (at when)
Process states • New • Running • Waiting • Ready • Terminated
Process state transition when? • New ready • Ready running • Running ready • Running waiting • Waiting ready • Running terminated
Process state transition when? • New ready : process creation completion • Ready running : scheduler dispatch • Running ready : time quantum expired, preempted by another process • Running waiting : I/O req. • Waiting ready : I/O completion • Running terminated : exit(), unexpected exceptions
PCB – process control block • Data structure of process inside kernel • task_struct in Linux • pidt_pid; /* process identifier */ long state; /* state of the process */ unsigned inttime_slice /* scheduling information */ structtask_struct *parent; /* this process’s parent */ structlist_head children; /* this process’s children */ structfiles_struct *files; /* list of open files */ structmm_struct *mm; /* address space of this process */
Context switching • Triggered by various events • Time quantum expired, I/O completion, etc. • Exchange running process with one of ready processes
Analogy in context switching, interrupt handling • When interrupt/context switching occurs, • Stop the current execution • Save regs on the PCB • Handle interrupt / exchange PCB (by scheduler) • Return to the previous execution • Load regs (values) back from PCB • PC / SP ? • Help of hw (arch.) • Return address reg. • Separate pc/sp for user applications
Scheduling – Choose a process to run • Scheduling queue: data structure for storing process in various states • Ready queue • Device queue
Summary page • Process concept • Cf. program • Memory layout • Address space • Execution context • PCB • Context switching • Scheduler operation • Process state diagram