operating systems - process

22
Operating Systems - process Seehwan Yoo Mse.cis.dku

Upload: yadid

Post on 14-Jan-2016

31 views

Category:

Documents


2 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Operating Systems - process

Operating Systems- process

Seehwan YooMse.cis.dku

Page 2: Operating Systems - process

Review

• Computer systems orga-nization (hardware)• Main components

• CPU: instruction execu-tion

• Memory: store data/in-struction (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 cpu interven-

tion

Page 3: Operating Systems - process

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

Page 4: Operating Systems - process

Process & execution con-text• 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

Page 5: Operating Systems - process

Program vs. process

Program • Stored in disk• No active execution

context• No PC, no SP, no run-

time data

Process• Loaded in memory• Has execution context• PC, SP, live registers,

open files, memory con-tents

Page 6: Operating Systems - process

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)

Page 7: Operating Systems - process

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

Page 8: Operating Systems - process

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• …

Page 9: Operating Systems - process

Time-sharing system’s im-plementation• 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 running process

• Scheduler determines which process to run (at when)

Page 10: Operating Systems - process

Process states

• New• Running• Waiting• Ready• Terminated

Page 11: Operating Systems - process

Process state transition di-agram

Page 12: Operating Systems - process

Process state transition when?• New ready• Ready running• Running ready• Running waiting• Waiting ready• Running terminated

Page 13: Operating Systems - process

Process state transition when?• New ready : process creation completion• Ready running : scheduler dispatch• Running ready : time quantum expired, pre-

empted by another process• Running waiting : I/O req.• Waiting ready : I/O completion• Running terminated : exit(), unexpected excep-

tions

Page 14: Operating Systems - process

PCB – process control block

• Data structure of process inside kernel• task_struct in Linux

• pid t_pid; /* process identifier */ long state; /* state of the process */ unsigned int time_slice /* scheduling information */ struct task_struct *parent; /* this process’s parent */ struct list_head children; /* this process’s children */ struct files_struct *files; /* list of open files */ struct mm_struct *mm; /* address space of this process */

Page 15: Operating Systems - process

Context switching

• Triggered by various events• Time quantum expired, I/O completion, etc.

• Exchange running process with one of ready pro-cesses

Page 16: Operating Systems - process

Scheduler - Switching the execution context

Page 17: Operating Systems - process

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

Page 18: Operating Systems - process

Scheduling – Choose a process to run• Scheduling queue: data structure for storing

process in various states• Ready queue• Device queue

Page 19: Operating Systems - process

Scheduling queues

Page 20: Operating Systems - process

Overall picture of schedul-ing

Page 21: Operating Systems - process

Let’s look into Scheduling in the next class!

Page 22: Operating Systems - process

Summary page

• Process concept• Cf. program

• Memory layout• Address space

• Execution context• PCB

• Context switching• Scheduler operation• Process state diagram