Process Process Creation / Termination
Process Process Creation / Termination
pause
n Queuing diagram:
queue
n Actual interleaved execution of the 4 enter dispatch
CPU
exit
processes:
(one Program Counter)
time
pause
process A
process B
process C
process A n CPU scheduling (round-robin)
process B
process C
process A ● Queue is first-in, first-out (FIFO) list
process C
process A
process D ● CPU scheduler takes process at head of
process C
process D queue, runs it on CPU for one time slice,
process C
then puts it back at tail of queue
3 Fall 1998, Lecture 05 4 Fall 1998, Lecture 05
Process Transitions in
Waiting on Something to Happen…
the Two-State Process Model
n When the OS creates a new process, it is n Some reasons why a process that might
initially placed in the not-running state otherwise be running needs to wait:
● It’s waiting for an opportunity to execute ● Wait for user to type the next key
● Wait for output to appear on the screen
n At the end of each time slice, the CPU
scheduler selects a new process to run ● Program tried to read a file — wait while
OS decides which disk blocks to read,
● The previously running process is paused and then actually reads the requested
— moved from the running state into the information into memory
not-running state (at tail of queue)
● Netscape tries to follow a link (URL) —
● The new process (at head of queue) is wait while OS determines address,
dispatched — moved from the not- requests data, reads packets, displays
running state into the running state requested web page
n If the running process completes its
execution, it exits, and the CPU scheduler n OS must distinguish between:
is invoked again
n If it doesn’t complete, but its time is up, it ● Processes that are ready to run and are
gets moved into the not-running state waiting their turn for another time slice
anyway, and the CPU scheduler chooses
a new process to execute ● Processes that are waiting for something
to happen (OS operation, hardware
event, etc.)
5 Fall 1998, Lecture 05 6 Fall 1998, Lecture 05
n The process state consists of (at least): n For every process, the OS maintains a
● Code for the program
Process Control Block (PCB), a data
structure that represents the process and
● Program’s static and dynamic data its state:
● Program’s procedure call stack ● Process id number
● Contents of general purpose registers ● Userid of owner
● Contents of Program Counter (PC) ● Memory space (static, dynamic)
—address of next instruction to be
executed ● Program Counter, Stack Pointer, general
purpose registers
● Contents of Stack Pointer (SP)
● Process state (running, not-running, etc.)
● Contents of Program Status Word (PSW)
— interrupt status, condition codes, etc. ● CPU scheduling information (e.g., priority)