Download - Operating Systems - process
Operating Systems- process
Seehwan YooMse.cis.dku
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
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 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
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
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 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)
Process states
• New• Running• Waiting• Ready• Terminated
Process state transition di-agram
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, pre-
empted by another process• Running waiting : I/O req.• Waiting ready : I/O completion• Running terminated : exit(), unexpected excep-
tions
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 */
Context switching
• Triggered by various events• Time quantum expired, I/O completion, etc.
• Exchange running process with one of ready pro-cesses
Scheduler - Switching the execution context
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
Scheduling queues
Overall picture of schedul-ing
Let’s look into Scheduling in the next class!
Summary page
• Process concept• Cf. program
• Memory layout• Address space
• Execution context• PCB
• Context switching• Scheduler operation• Process state diagram