L04_Processes_2

advertisement
Processes 2
Introduction to Operating Systems: Module 4
Process states
create
dispatch
activate
ready
inactive
running
pre-empt block
terminated
suspend
wakeup
terminate
waiting
Process states
 Inactive
(New or Suspended)
Process has been initiated; the OS has not yet allocated it any
memory resources
 Process has been active, OS needs to reduce the degree of
multiprogramming to improve system performance

 Ready

Process has some code and data in memory, is eligible to get CPU
 Running
The CPU is currently executing code for this process
 In single processor system, only one process is running at a time

Process states
 Waiting

(Blocked)
Process is in a queue waiting for some device or system resource
 Terminated

Program is done; process resources need to be recovered
(accounting)
Operations on processes: creation
 When
a process is created, the operating system updates its
data structures to include the new process
 Allocation of memory resources does not occur until
activation, though the process may be stored on disk
 UNIX examples
fork system call creates new process
 execve system call used after a fork to replace the process’
memory space with a new program

Operations on processes: creation
 Reasons
for process creation
User logs on
 User starts a program
 OS creates process to provide a service
(e.G., Printer daemon to manage printer)
 Program starts another process
(e.G., Netscape calls xv to display a picture)

Operations on processes: termination
 When
a process is terminated, the operating system must
free its resources and remove it from OS data structures
 Reasons for process termination
Normal completion
 Arithmetic error, or data misuse (e.G., Wrong type)
 Invalid instruction execution
 Insufficient memory available, or memory bounds violation
 Resource protection error
 I/O failure

Operations on processes
 Preempt
a process (running  ready)
Process’ time quantum expires
 Higher priority process arrives at the ready queue

 Block

a process (running  waiting)
begin waiting for I/O, resource
 Wakeup

a process (waiting  ready)
when notified I/O complete or resource is available
Operations on processes
 Dispatch

Called on process at head of CPU queue after preempt or block
 Change

the priority of a process
in UNIX, the nice command
 Suspend



a process (ready  inactive)
Used to reduce the system load during a peak loading situation
Process state is stored on disk
 Activate

a process (ready  running)
a process (inactive  ready)
Brings a new inactive process into memory
Resumes the execution of a suspended process
Swapping
 What
if memory cannot hold all processes?
 Don't
allow the creation of more processes
 What about existing processes?
 Dynamically
allocated memory
 Some
processes need to have their address space
written to disk so that others can continue
 Such
processes are said to be swapped to disk
 Modern
OSs don't swap out entire processes, they can
selective "swap" parts of the address space
• We'll learn more of this when we study memory management
Process control block (PCB)
 Representation
of a process
 Used to save and restore process
context
 Exact contents are system
dependent

process
next
state
previous
process id
program counter
registers
May reside in linked lists
 When
is the PCB read from
memory? Written to memory?
memory structure
open file table
etc
Download