Operating Systems Week 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Presented by: Lecturer.

Mahpara Tunio
PROCESS
 A process is a program at the time of execution.
 Differences between Process and Program
 PROCESS
 Process is a dynamic object
 Process is sequence of instruction execution
 Process loaded in to main memory
 Time span of process is limited
 Process is a active entity
PROGRAM
 Program is a static object
 Program is a sequence of instructions
 Program loaded into secondary storage devices
 Time span of program is unlimited
 Program is a passive entity
Process States
 When a process executed, it changes the state,
generally the state of process is determined by the
current activity of the process.
 Each process may be in one of the following states:
 1. New : The process is being created.
 2. Running : The process is being executed.
 3. Waiting : The process is waiting for some event to
occur.
 4. Ready : The process is waiting to be assigned to a
processor.
 5. Terminated : The Process has finished execution.
Only one process can be running in any processor at
any time, But many process may be in ready and
waiting states. The ready processes are loaded into a
“ready queue”.
 a) New ->Ready : OS creates process and prepares the
process to be executed, then OS moved the process
into ready queue.

 b) Ready->Running : OS selects one of the Jobs from


ready Queue and move them from ready to Running.

 c) Running->Terminated : When the Execution of a


process has Completed, OS terminates that process
from running state.
 Sometimes OS terminates the process for some other
reasons including Time exceeded, memory
unavailable, access violation, protection Error, I/O
failure and soon.
 d) Running->Ready : When the time slot of the
processor expired (or) If the process or received any
interrupt signal, the OS shifted Running ->
ReadyState.
 e) Running -> Waiting : A process is put into the
waiting state, if the process need an event occur (or)
an I/O Devicerequire.
 f) Waiting->Ready : A process in the waiting state is
moved to ready state when the event for which it has
been Completed.
 Process Control Block:
Each process is represented in the operating System by a
Process Control Block.
It is also called Task Control Block. It contains many
pieces of information associated with a specific Process.
Process control block
 Process Control Block
 1. Process State : The State may be new, ready,
running, and waiting, Terminated…
 2. Program Counter : indicates the Address of the next
Instruction to be executed.
 3. CPU registers : registers include accumulators, stack
pointers, General purpose Registers….
 4. CPU-Scheduling Info : includes a process pointer,
pointers to scheduling Queues, other scheduling
parameters etc.
 5. Memory management Info: includes page tables,
segmentation tables, value of base and limit registers.

 6. Accounting Information: includes amount of CPU


used, time limits, Jobs(or)Process numbers.

 7. I/O Status Information: Includes the list of I/O


Devices Allocated to the processes, list of open files.
Threads:
 A process is divide into number of light weight
process, each light weight process is said to be a
Thread.
 The Thread has a program counter (Keeps track of
which instruction to execute next), registers (holds its
current working variables), stack (execution History).
 Thread States:
 1. bornState : A thread is just created.
 2. readystate : The thread is waiting for CPU.
 3. running : System assigns the processor to thethread.
4. sleep : A sleeping thread becomes ready after the
designated sleep time expires.
 5. dead : The Execution of the thread finished.
 Eg: Word processor.
 Typing, Formatting, Spell check, saving are threads.
Differences between Process and Thread
Multithreading
 A process is divided into number of smaller tasks each task is
called a Thread.
 Number of Threads with in a Process execute at a time is called
Multithreading. If a program, is multithreaded, even when some
portion of it is blocked, the whole program is not blocked. The
rest of the program continues working If multiple CPU’s are
available.
 Multithreading gives best performance. If we have only a single
thread, number of CPU’s available, No performance benefits
achieved.
 Process creation is heavy-weight while thread creation is light-
weight Can simplify code, increase efficiency
 CODE- Contains instruction
 DATA- holds global variable
 FILES- opening and closing files
 REGISTER- contain information about CPU state
STACK-parameters, local variables, functions
Types Of Threads:
 1) User Threads : Thread creation, scheduling,
management happen in user space by Thread Library.
user threads are faster to create and manage.
 If a user thread performs a system call, which blocks it,
all the other threads in that process one also
automatically blocked, whole process is blocked.
 Advantages
 Thread switching does not require Kernel mode
privileges.
 User level thread can run on any operating system.
 Scheduling can be application specific in the user level
thread.
 User level threads are fast to create and manage.
 Disadvantages
 In a typical operating system, most system calls are
blocking. Multithreaded application cannot take
advantage of multiprocessing.
 Kernel Threads: kernel creates, schedules, manages
these threads .these threads are slower, manage. If one
thread in a process blocked, over all process need not
be blocked.
 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 requires a mode switch to the Kernel.

You might also like