Transcript Processes

OPERATING SYSTEMS
PROCESSES
TANNENBAUM, SECTION 2-1
DEFINITION: PROCESS
• Program in execution
• Current value of program counter
• Values of registers
• Values of variables
THE PROCESS MODEL (1)
Four Independently Scheduled Processes
THE PROCESS MODEL (2)
Only one program is active at once.
STATES
• Processes go through a series of discrete states
• Running State
• Process currently has cpu
• Ready state
• Could use cpu if one were available
• Blocked state
• Waiting for some event to happen, say i/o completion
LISTS
• Assume a single CPU system
• 1 process can run at a time
• Several process may be ready
• Several processes may be blocked
• Two Lists
• Priority queue of ready processes
• Unordered list of blocked processes
• Unordered because processes become unblocked in the order
in which the resources they require become available.
EXAMPLE
• Process A pty 1 waiting for keyboard input
• Process B pty 2 waiting for printer
• Process C pty 3 waiting for disk input
Where 3 is highest
If Process A gets input before C gets input, we
shouldn’t hold process A
STATES (2)
Tanenbaum & Bo,Modern Operating Systems:4th ed., (c) 2013 Prentice-Hall, Inc. All rights reserved.
READY TO RUNNING
• Job is admitted to system
• Process created and placed in ready queue
• Gradually makes its way to the head of the queue
• When CPU is available, scheduled (dispatched)
RUNNING TO READY
• Process exhausts quantum
• Clock generates an interrupt
• o/s dispatches highest priority ready process
RUNNING TO BLOCKED
• Running process does i/o op
• Blocks itself
BLOCKED TO READY
• Event for which process was waiting completes
• Process is added to priority queue
PROCESS TABLE
• Every O/S has a process table
•
•
•
•
1 entry per process, called the PCB
PCB is a record (struct)
Process table is an array of pointers to structs
Each process is uniquely identified by its PCB
PROCESS CONTROL BLOCK
• PCB is what defines a process to the system
• Current state of the process (running, ready,
blocked)
• Unique id of the process
• Pointer to the process’ parent
• Pointer to each child process
• Process’ priority
• Pointer to process’ memory
• Pointer to allocated resources (printers, disk drives,
unacknowledged messages)
• Register save area
• File descriptors
• Processor that process is running on
EXAMPLE: FORK
int fork()
• Returns
• -1: no process was created
• 0: returned to the child process
• pid: returned to parent process
• Creates
• Copy of parent process but with its own pid and a different
parent pid
EXAMPLE: WAIT
• int* status
int wait(status)
• Suspends calling process until it receives a signal to
wakeup
• Returns (in the case of a fork)
• pid of child
• -1 if childless
• See example 10 on the website
MODELING MULTIPROGRAMMING
• Suppose a process spends a fraction, p, of
its time waiting for i/o.
• That is, at any randomly chosen time, the
probability that the process is blocked
waiting for i/o is p.
• With n processes, the probability that all are
waiting for i/o = pn
• So, the probability that the cpu is used = 1 –
pn
MODELING MULTIPROGRAMMING (2)
CPU use as a function of the number of processes in
memory (i.e., n). As prob. of i/o blocking increases, cpu
use increases with more processes. Of course, the more
memory, the more processes.