Documente Academic
Documente Profesional
Documente Cultură
2
Topics under Process Mgmt:
Process concepts and states
Scheduling (CPU and I/O)
Synchronization (concurrency)
Deadlock handling
OS Responsibilities for Process
Mgmt.
Creating and deleting of process
Scheduling of a process (suspending and
resuming the execution of process)
Process synchronization
Process communication
Deadlock handling
What is a process?
Process
– Program in execution needing resources (such
as CPU time, memory, files and I/O devices) to
accomplish its tasks.
- Executing set of machine instructions
- Execution of a process must progress in a sequential
fashion; at most one instruction is executed on behalf of
the process.
Components of a process
Code
Data
Resources
Status
Threads
Classification of OS according to the
types of system:
Single-process single-threaded – only one
process can execute at a time. Once a process is
allocated to the CPU, that process runs to
completion before any other process can
execute.
Example: DOS
Classification of OS according to the
types of system:
Multi-process single threaded – a single
entity (the process), is the object upon which
both resource allocation and CPU scheduling are
performed.
Example: UNIX
Classification of OS according to the
types of system:
Multi-process multi-threaded – resources are
allocated to the processes but CPU scheduling
can be in terms of thread.
Multiprogramming
allows more than one process (e.g. concurrent
execution of many processes)
How can several processes share
one CPU?
OS takes care of this by making sure that:
kill
Event occurs dispatch
or resource
available error
Blocked
Blocked
State transition
_____ internal
_ _ _ _external
Additional process states
Medium term scheduling adds two additional
process states:
Swapped blocked – process is waiting for some
event to occur and has been swapped out to
secondary storage
Swapped-ready – process is ready to run but is
swapped out to secondary storage and may not be
allocated to the CPU since it is not in main
memory.
Process Control Block (PCB)
Each process is represented in the OS by a PCB.
It is where collection of process information are
kept and accessed.
Loop forever
{
run the process for a while
stop process and save its state
load the state of another process
}
Dispatcher
Process
Process22
Process
Processnn
Process
Process
11
CPU
CPU
Operating
System dispatcher
dispatcher
Ready
queue
Control of the CPU
The CPU can only do one thing at a time. While a
user process is running, dispatcher cannot run
thus the OS may lose control.
How does the dispatcher regain control
of the CPU?
Trust the process to wake up the dispatcher
when done (sleeping beauty approach)
Not a good solution because sometimes process
loop indefinitely
Provide a mechanism to wake the dispatcher
(alarm clock)
Scheduling queues
Job queue
Set of all processes that enter the system
Ready queue (linked-list)
Set of all processes residing in main memory,
ready and waiting to execute.
Device queues
Set of processes waiting for an I/O device, each
device has a device queue.
Queuing diagram:
Long-term scheduler (or job
scheduler)
Selects which processes should be brought into
the ready queue; these processes are spooled to
a mass-storage (disk) where they are kept for
later execution.
Swapping
Removing a process from the memory.
Medium-term scheduler
Context switch
When a CPU switches to another process, the
system must save the state of the old
process and load the saved state of the
new process
Computation Speedup
Tasks are broken down into subtasks, each of
which is executing in parallel with the others
Issues with cooperating system
Requires mechanism to allow processes to
communicate with one another and to
synchronize their actions
Shared memory
Message passing (interprocess communication)
Issues with cooperating system
May give rise to a race condition during critical
section processing which may lead to
inconsistent states / data.
shared
Process B M
M
Process B
M
Kernel M
Kernel
Kernel thread
Supported and managed directly by the OS.
Multithreading models
Many to one model
Maps many user-level threads to one kernel
thread.
Older versions of Solaris uses this model
User thread
K Kernel thread
Multithreading models (cont)
One to one model
Maps each thread to a kernel thread.
Provides more concurrency than Many to one
model.
Allows multiple threads to run in parallel on
multiprocessors
Drawback: user thread requires creating
kernel thread (suffers performance)
Linux, Windows (starting Win 95 onwards)
and Solaris 9 use this model.
One to one model
User thread
K Kernel thread
K K K
Multithreading models (cont)
Many to many model
Multiplexes many user-level threads to a
smaller or equal number of kernel threads
Can create as many user threads, and the
kernel threads can run in parallel on a
multiprocessor.
IRIX, HP-UX, and TRu64UNIX use this model.
Many to many model
User thread
K K Kernel thread
K