0% found this document useful (0 votes)
2 views10 pages

Os Module Two NNotes

The document outlines the various states of a process during execution, including New, Ready, Executing, Waiting, and Terminated, along with their transitions. It also describes the Process Control Block (PCB) as a data structure used by the operating system to track process information and manage scheduling. Additionally, it discusses context switching, types of threads, multithreading models, and scheduling algorithms, emphasizing the differences between preemptive and non-preemptive scheduling.

Uploaded by

fapih97391
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Os Module Two NNotes

The document outlines the various states of a process during execution, including New, Ready, Executing, Waiting, and Terminated, along with their transitions. It also describes the Process Control Block (PCB) as a data structure used by the operating system to track process information and manage scheduling. Additionally, it discusses context switching, types of threads, multithreading models, and scheduling algorithms, emphasizing the differences between preemptive and non-preemptive scheduling.

Uploaded by

fapih97391
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q?

1 Process States Diagram

Process States
- During execu on, process changes its state. Process state shows the current ac vity
of the process. Process state contains five states.
- Each process remains in one of these five states. There is a queue associated with
each state of the process.
- Process resides on that queue as per the state in which it resides.

1. New state
The new process being created.
2. Ready state
A process is ready to run but it is wai ng for CPU being assigned to it.
3. Execu ng state
A process is said to be in running state if currently CPU is allocated to it and it is
execu ng.
4. Wai ng (blocked) state
A process can’t con nue the execu on because it is wai ng for event to happen such
as I/O comple on. Process is able to run when some external event happens.
5. Terminated state
The process has completed execu on.
Process State Transi on Diagram (Explana on)
 When the process is created, it remains in new state.
 A er the process admi ed for execu on, it goes in ready state. A process in this state,
wait in the ready queue. Scheduler dispatches the ready process for execu on i.e.
CPU is now allocated to the process.
 When CPU is execu ng the process, it is in execu ng state. A er context switch,
process goes from execu ng to ready state. If execu ng process ini ates an I/O
opera on before its allo ed me expires, the execu ng process voluntarily give up
the CPU.
 In this case process transit from execu ng to wai ng state. When the external event
for which a process was wai ng happens, process transit from wai ng to ready state.
When process finishes the execu on, it transit to terminated state.
Q?2 Process Control Block (PCB)

Process Control Block (PCB)


 Any process is iden fied by its Process Control Block (PCB). PCB is the data structure
used by the opera ng system to keep track on the processes.
 All the informa on associated with process is kept in process control block. There is
separate PCB for each process.
 Traffic controller module keeps track on the status of the process. PCB’s of the
processes which are in the same state (ready, execu ng, wai ng etc) are linked
together giving a specific name to the list such as ready list.
 If many processes wait for the same device, then PCBs of all these processes are
linked together in chain wai ng for that device.
 If device becomes free then traffic controller checks the PCB chain to see if any
process is wai ng for the device.
 If the processes are available in that device chain, then again it is placed back to ready
state to request that device again.
Fig. Process Control Block (PCB)

Pointer
 This field points to other process’s PCB. The scheduling list is maintained by pointer.
Current state
 Currently process can be in any of the state from new, ready, execu ng, wai ng etc as
described above.
Process ID
 Iden fica on number of the process. Opera ng system assign this number to process
to dis nguish it from other processes.
Priority
 Different process can have different priority. Priority field indicate the priority of the
process.
Program counter
 A er context switch, CPU is given to other process. When turn of the previously
execu ng process comes, again CPU gets allocated to it. Program counter contains
address of the instruc on from which execu on resumes a er context switch.
Registers
 It includes general purpose register, index registers, stack pointers and accumulators
etc. number of register and type of register differs as per the architecture of
computer. The state informa on stored a er interrupt is again used by the process to
resume the execu on.
Accoun ng
 Informa on for calcula ng the process’s priority rela ve to other processes. This may
include accoun ng informa on about resource use so far. It also includes amount of
CPU me and real me used, me limits, process numbers and so on.
Memory alloca on
 This informa on may include the value of base and limit register. It includes paging,
segmenta on related informa on depending on the memory system used. Address
space allocated to the process etc.
Event informa on
 For a process in the blocked state this field contains informa on concerning the event
for which the process is wai ng.
List of open files
 Files opened by the process.
Q?3 Context Switching

Context Switching
 When CPU switches from one process to other, a context switch occurs. A context
switch is the switching of the CPU (Central Processing Unit) from one process or
thread to another.
 When context switch occurs, opera ng system restores the informa on of currently
execu ng process for the later use.
 When CPU again gets allocated to the same process, the restored informa on is used
to resume the execu on.
 The context of a process is represented in the Process Control Block (PCB) of a
process.
 The informa on needs to be restored includes address of the next instruc on to be
executed (program counter), CPU register contents, pointers to the memory allocated
to the process, scheduling informa on, changed state, I/O state, accoun ng
informa on etc.
 While context switch, system does not perform any useful work. So context switch is
pure overhead on the system.
 The speed of context switching depends on the number of registers that must be
copied, memory speed. So context switch speed varies from system to system.
Q?4 Types Of Threads

Types of Threads
1. User Level Threads
2. Kernel Level Threads

User Level Threads


- In user level implementa on, kernel is unaware of the threads. In this case, thread
package en rely put in user space. Java language supports threading package.
- User can implement the mul threaded applica on in java language.
- Kernel treats this applica on as a single threaded applica on. In a user level
implementa on, all of the work of thread management is done by the thread
package.
- Thread management includes crea on and termina on of thread, messages and data
passing between threads, scheduling thread for execu on, thread synchroniza on
and a er context switch saving and restoring thread context etc.
- Crea on and destroying of thread requires less me and is cheap opera on. It is the
cost of alloca ng memory to set up a thread stack and deal loca ng the memory
while destroying the thread.
Kernel Level Threads
- In this, threads are implemented in opera ng system’s kernel. The thread
management is carried out by kernel.
- All these thread management ac vi es are carried out in kernel space. So thread
context and process context switching becomes same.
- Applica on can be wri en as mul threaded and threads of the applica on are
supported as threads in single process.
Q?5 Mul threading Models

Types of mul threading models


 One to one
 Many to one
 Many to many

1. One to one model


 In this model rela onship between user level thread and kernel level thread is one to
one. It means that there is mapping of a single user level thread to a single kernel
level thread.
 Because of such type of rela onship mul ple threads executes in parallel leading to
more concurrency.
 However, since it is needed to create kernel thread for every crea on of user thread.
So applica on performance will be degraded.
 Windows series and Linux opera ng systems try to minimize this problem by
restric ng the expansion of the thread count. OS/2, Windows NT and windows 2000
are one to one rela onship model.
2. Many to one model
 In this model rela onship between user level thread and kernel level thread is many
to one. It means that there is mapping of many user level threads to a single kernel
level thread.
 In this model management is done in user space. When one thread makes a system
call for blocking, the en re process gets blocked.
 At a me only one thread can access the Kernel thread at a me, so many other
threads cannot execute in parallel on mul ple processors.
 Therefore concurrent execu on of threads cannot be achieved. This type of
rela onship facilitates an effec ve context-switching environment, easily
implementable even on simple kernels with no thread support.
3. Many to Many model
 Many to many associa on exist between user level thread and kernel level thread in
this model.
 It means that more number of user level threads are allied to equal or less number of
kernel level threads.
 The necessity of altering code both in kernel and user spaces leads to a level of
complexity not present in the one to one and many to one model.
 Like many-to-one model, this model offers an efficient context-switching environment
as it repels from system calls.
 The keen complexity offers the poten al for priority inversion and subop mal
scheduling with minimum coordina on between the user and kernel schedulers.
Q?6 Types of Scheduling Algorithms

1. Non-Preemp ve
 Non-preemp ve algorithms are designed so that once a process is allocated to CPU, it
does not free CPU un l it completes its execu on.

2. Preemp ve
 Preemp ve algorithms allow taking away CPU from process during execu on.
 If highest priority process arrives in the system, CPU from currently execu ng low
priority process is allocated to it.
 It ensures that always highest priority process will be execu ng.

Preemp ve Scheduling Non-Preemp ve Scheduling

CPU can be taken away from a running CPU cannot be taken away un l process
process. completes.

More responsive for high-priority


Less responsive.
processes.

Suitable for me-sharing systems. Suitable for batch systems.

More complex to implement. Simpler to implement.

Causes overhead due to context switching. No overhead of context switching.

Example: Round Robin, Priority


Example: FCFS, SJF (non-preemp ve)
(preemp ve)

You might also like