Operating System Cha 2
Operating System Cha 2
processor.
A unit of activity characterized by the execution of a
2
sequence of instructions.
Comparison between program and process
Program Process
A program consists of a set of A process is a sequence of
instructions in a programming instruction execution
language
All ready processes are kept in a queue and they keep waiting for
CPU.
computer architecture.
process terminates.
10
7. Accounting information: Includes the amount of
CPU and real time used, time limits, job or process
numbers, account numbers etc.
12
Con’t…
Note: When we say that the process are listed together, we mean
that actually their PCBs are linked together.
o The header of the queue contains two pointers:
The first pointer points to the first PCB.
14
The second points to the last PCB in the list.
3. Device queue: Some of process which are blocked due to
unavailability of an I/O device.
- These processes form a device queue.
when the CPU picks a process for its execution then a change
in the state of the process occurs.
If it’s state is changed to block, it is added to the device queue
V.
16
Get process information
I. Process creation:
It is the job of an OS to create process.
There are four ways of achieving it.
For a batch environment, a process is created in a response to the
submission of a job, usually tape and disk .
In an interactive environment, a process is created when a new
user attempts to log on.
The OS can create a process, to perform a function on behalf of a
user program.
Spawned by existing process (A number of processes can be
generated from the main process), For the purpose of modularity or
17
to exploit parallelism.
II. Process Termination: Two types of termination
A. Normal Termination
B. Forced Termination
continue.
-This is known as cascading termination.
19
Cooperating Processes
Two process are said to be “serial” if the execution of one must
Computation speed-up
Modularity
Convenience
21
2.2. The Threads Concept
Introduction:
A thread is similar to a sequential program, like a
Efficient communication.
threads.
Utilization of multiprocessor architectures to a greater scale and
efficiency
Disadvantages
More complicated code
25
Deadlocks
Types of Thread
Threads are implemented in following two ways:
Advantages
Thread switching does not require Kernel mode privileges.
User level thread can run on any operating system.
Disadvantages
In a typical operating system, most system calls are blocking.
28 multiprocessing.
II. Kernel Level Threads
Thread management done by the Kernel.
single process.
The Kernel performs thread creation, scheduling and management
29 in Kernel space.
Advantages and Disadvantages of Kernel Level Threads
Advantages
Kernel can simultaneously schedule multiple threads from the same
process on multiple processes.
If one thread in a process is blocked, the Kernel can schedule
another thread of the same process.
Kernel routines themselves can multithreaded.
Disadvantages
Kernel threads are generally slower to create and manage than the
user threads.
Transfer of control from one thread to another within same process
30
requires a mode switch to the Kernel.
Difference between User Level & Kernel Level
Thread
31
2.3. Multithreading and thread usage
Multithreading:
Multithreading is similar to multitasking, but enables
33
Multithreading Models
Multithreading models are three types
1. Many to Many Model
Many user level threads multiplexes to the Kernel
thread of smaller or equal numbers.
The number of Kernel threads may be specific to either
a particular application.
34
2. Many to One Model
Maps many user level threads to one Kernel level thread.
35
3. One to One Model
There is one to one relationship of user level thread to the
kernel level thread.
Provides more concurrency than the many to one model.
microprocessors.
Disadvantage: creating user thread requires the
36
2.4. Inter process communication
Cooperating process require IPC to exchange data and
information.
Mechanism for processes to communicate and to
asynchronous, buffering)
39
Implementation Questions
How are links established?
Can a link be associated with more than two processes?
How many links can there be between every pair of
communicating processes?
What is the capacity of a link?
Is the size of a message that the link can accommodate
fixed or variable?
Is a link unidirectional or bi-directional?
40
Direct Communication
Properties of communication link:
communicating processes.
Between each pair there exists exactly one link
41
bi-directional
processes must explicitly name the receiver or
sender of a message:
I. Symmetric Addressing:
• Send (P, message):- Send a message to process P
• Receive (Q, message):- Receive a message from process Q
referred to as ports)
Processes can communicate only if they share a mailbox
links.
43
• Link may be unidirectional or bi-directional
Operations:
• Destroy a mailbox
Solutions
operation
• Allow the system to select arbitrarily the receiver, Sender
45 is notified who the receiver was.
Synchronization
Message passing may be either blocking or non-blocking
received
• Blocking receive: has the receiver block until a message is
available
Non-blocking is considered asynchronous
in a temporary queue.
Such queues can be implemented in one of three ways
3.
47
Unbounded capacity:- infinite length, Sender never waits
Race Condition
A race condition is defined as the situation in which
CPU Scheduler.
Depends on which process "wins" the "race".
critical sections.
and there exist some processes that wish to enter their critical
section, then the selection of the processes that will enter the
request is granted
51 speed
Two approaches depending on if kernel is
preemptive or non-preemptive