Operating System I Processes Processes F A program

  • Slides: 12
Download presentation
Operating System I Processes

Operating System I Processes

Processes F “A program in execution” F Modern computers allow several at once –

Processes F “A program in execution” F Modern computers allow several at once – “pseudoparallelism” A Program Counter B C A B C Conceptual View A B C Time

Processes F “A program in execution” main() {. . . } A() { …

Processes F “A program in execution” main() {. . . } A() { … } Heap A Stack main • “more” than a program: ls, tcsh • “less” than a program: gcc blah. c (cpp, cc 1, cc 2, ln …) F “A sequential stream of execution in it’s own address space”

Process States F Consider: cat /etc/passwd | grep claypool Exit New Running Dispatch I/O

Process States F Consider: cat /etc/passwd | grep claypool Exit New Running Dispatch I/O Wait Interrupt Ready I/O Complete Waiting (Hey, you, show states in top!)

Design Technique: State Machines F Process states F Move from state to state based

Design Technique: State Machines F Process states F Move from state to state based on events – Reactive system F Can be mechanically converted into a program F Other example: – string parsing, pre-processor

Unix Process Creation F System call: fork() – creates (nearly) identical copy of process

Unix Process Creation F System call: fork() – creates (nearly) identical copy of process – return value different for child/parent F System call: exec() – over-write with new process memory F (Hey, you, show demos!)

Java Process Creation F “fork” and “exec” rolled into exec() public Process exec(String command)

Java Process Creation F “fork” and “exec” rolled into exec() public Process exec(String command) – args separated by whitespace F Child Process output: – get. Output. Stream() – get. Input. Stream() – get. Error. Stream() F Depends status: - wait. For() - exit. Value() - destroy() upon underlying OS proc support!

Process Scheduler cat ls . . . disk vid Scheduler F All services are

Process Scheduler cat ls . . . disk vid Scheduler F All services are processes F Small scheduler handles interrupts, stopping and starting processes

Process Control Block F Each process has a PCB – state – program counter

Process Control Block F Each process has a PCB – state – program counter – registers – memory management –… F OS keeps a table of PCB’s, one per process F (Hey! Simple Operating System, “system. h”)

Question F Usually the PCB is in OS memory only. F Assume we put

Question F Usually the PCB is in OS memory only. F Assume we put the PCB into a processes address space. F What problems might this cause?

Interrupt Handling F Stores program counter F Loads new program counter – jump to

Interrupt Handling F Stores program counter F Loads new program counter – jump to interrupt service procedure F Save PCB information F Set up new stack F Set “waiting” process to “ready” F Re-schedule (probably awakened process) F If new process, called a context-switch

Context Switch F Pure overhead F Fast, fast – typically 1 to 1000 microseconds

Context Switch F Pure overhead F Fast, fast – typically 1 to 1000 microseconds F Sometimes special hardware to speed