0% found this document useful (0 votes)
20 views

3

Uploaded by

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

3

Uploaded by

SujaChavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

3.

Process Management
Process ://2marks
A Program does nothing unless its instructions are executed by a CPU. A program
in execution is called a process. For example, when we write a program in C or C+
+ and compile it, the compiler creates binary code. The original code and binary
code are both programs. When we actually run the binary code, it becomes a
process.

What does a process look like in memory?

Text Section:A Process, sometimes known as the Text Section, also includes the
current activity represented by the value of the Program Counter.
Stack: The Stack contains the temporary data, such as function parameters, returns
addresses, and local variables.
Data Section: Contains the global variable and static variables .
Heap Section: Dynamically allocated memory to process during its run time.

Process states ://imp imp 4marks


The process, from its creation to completion, passes through various states. The
minimum number of states is five.
 NEW- The process is being created.
 READY- The process is ready to run but it is waiting to be assigned to a
processor.
 RUNNING- A process is said to be in running state if currently CPU is
allocated to it and it is executing.
 WAITING- The process is waiting for some event to occur(such as an I/O
completion or reception of a signal).
 TERMINATED- The process has finished execution.
Process Control Block ://4marks /2 marks
Process Control Block is a data structure that contains information of the process
related to it. The process control block is also known as a task control block, entry
of the process table, etc.
Each process is represented as a process control block (PCB) in the operating
system.

 Process state – It indicates current state of a process. Process state can be new,
ready, running, waiting and terminated.
 Process ID – Every process is assigned with a unique id known as process ID
or PID which stores the process identifier.
 Priority :Priority of the process.
 Program counter: The program counter lets you know the address of the next
instruction, which should be executed for that process.
 Registers
This specifies the registers that are used by the process. They may include
accumulators, index registers, stack pointers, general purpose registers etc.
 Accounting information
This information includes the amount of CPU used, time limits, account
holders, job or process number and so on. It also includes information about
listed I/O devices allocated to the process such as list of open files.
 Memory Management Information
The memory management information includes the page tables or the
segment tables depending on the memory system used. It also contains the
value of the base registers, limit registers etc.
 Open files list – This information includes the list of files opened for a
process.

Process Queues
The Operating system manages various types of queues for each of the process
states. The PCB related to the process is also stored in the queue of the same state.
If the Process is moved from one state to another state then its PCB is also
unlinked from the corresponding queue and added to the other state queue in which
the transition is made.

The Operating System maintains the following important process scheduling


queues −
 Job queue − This queue keeps all the processes in the system.
 Ready queue − This queue keeps a set of all processes residing in main
memory, ready and waiting to execute. A new process is always put in this
queue.
 Device queues − The processes which are blocked due to unavailability of
an I/O device constitute this queue.
Schedulers //4 marks
Schedulers are special system software which handle process scheduling in
various ways. Their main task is to select the jobs to be submitted into the system
and to decide which process to run. Schedulers are of three types −
 Long-Term Scheduler
 Short-Term Scheduler
 Medium-Term Scheduler

1. Long term scheduler:


It selects programs from job pool and loads them into the main
memory.
It controls the degree of multiprogramming. The degree of
multiprogramming is the number of processes loaded (existing) into the
main memory.
System contains I/O bound processes and CPU bound processes.
An I/O bound process spends more time for doing I/O operations whereas
CPU bound process spends more time in doing computations with the CPU.
So It is the responsibility of long term scheduler to balance the system by
loading some I/O bound and some CPU bound processed into the main
memory. Long term scheduler executes only when a process leaves the
system, so it executes less frequently. When long term scheduler selects a
process from job pool, the state of process changes from new to ready state.
2.Short Term Scheduler
It is also called as CPU scheduler. Its main objective is to increase system
performance in accordance with the chosen set of criteria. It is the change of
ready state to running state of the process. CPU scheduler selects a process
among the processes that are ready to execute and allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which
process to execute next. Short-term schedulers are faster than long-term
schedulers.

3.Medium term scheduler:


When a process is in running state, due to some interrupt it is blocked. System
swaps out blocked process and store it into a blocked and swapped out process
queue.
When space is available in the main memory, the operating system looks at the list
of swapped out but ready processes.
The medium term scheduler selects one process from that list and loads it into the
ready queue.
The job of medium term scheduler is to select a process from swapped out
process queue and to load it into the main memory.
This scheduler works in close communication with long term scheduler for loading
process into the main memory.
Comparison among Scheduler//4marks -4point
S.N Long-Term Short-Term Medium-Term
. Scheduler Scheduler Scheduler

1 It is a job scheduler It is a CPU It is a process


scheduler swapping scheduler.

2 Speed is lesser than Speed is fastest Speed is in between


short term scheduler among other two both short and long
term scheduler.

3 It controls the It provides lesser It reduces the degree


degree of control over degree of
multiprogramming of multiprogramming.
multiprogramming

4 It is almost absent It is also minimal in It is a part of Time


or minimal in time time sharing system sharing systems.
sharing system

5 It selects processes It selects those It can re-introduce


from job pool and processes which are the process into
loads them into ready to execute memory and
memory for execution can be
execution continued.

With neat diagram explain inter process communication model.//6marks imp


imp
Inter-process communication:
Inter Process Communication (IPC) refers to a mechanism, where the operating
systems allow various processes to communicate with each other. This involves
synchronizing their actions and managing shared data.
There are two models of IPC
1.Shared memory

In this, all processes who want to communicate with other processes can access a
region of the memory residing in an address space of a process creating a shared
memory segment.
All the processes using the shared memory segment should attach to the address
space of the shared memory. All the processes can exchange information by
reading and/or writing data in shared memory segment.
The form of data and location are determined by these processes who want to
communicate with each other.
These processes are not under the control of the operating system.
The processes are also responsible for ensuring that they are not writing to the
same location simultaneously.
After establishing shared memory segment, all accesses to the shared memory
segment are treated as routine memory access and without assistance of kernel.

2. Message Passing
In this model, communication takes place by exchanging messages between
cooperating processes.
It allows processes to communicate and synchronize their action without sharing
the same address space.
It is particularly useful in a distributed environment when communication process
may reside on a different computer connected by a network.
Communication requires sending and receiving messages through the kernel.

The processes that want to communicate with each other must have a
communication link between them. Between each pair of processes exactly one
communication link.

b) Explain context switch with suitable example.


Context switch
 Switch the CPU to another process requires saving the state of old process and
loading the saved state for new process. This task is known as a context switch.
The context switch represented with PCB.
 Saves context of old process in its PCB and loads context of new process
schedule to run.
To make context switching time to be less, registers which are the fastest access
memory are used.
Information to be stored for context switching in PCB is:-
1) program counter 2) Scheduling information 3) Changed state 4) Accounting
Information 5) Base and Limit regsiter
Thread :
Thread is an execution unit that is part of a process. A process can have multiple
threads.It is a unit of execution in concurrent programming. A thread is lightweight
and can be managed independently by a scheduler. It helps you to improve the
application performance using parallelism.
The process can be split down into so many threads. For example, in a browser,
many tabs can be viewed as threads.
Difference between Process and Thread//4marks
Process Thread
Program in execution called as Thread is part of process. It is light
Process.It is heavy weight process. weight process.
Processes require more time for context Threads require less time for context
switching as they are more heavy. switching as they are lighter than
processes.
Processes are totally independent and A thread may share some memory with
don’t share memory. its peer threads.
Processes require more resources than Threads generally need less resources
threads. than processes.
Processes have independent data and A thread shares the data segment, code
code segments. segment, files etc. with its peer threads.
Processes require more time for Threads require less time for creation.
creation.
Individual processes are independent of Threads are parts of a process and so are
each other. dependent.

Explain any four benefits of using threads.


1. Responsiveness:
If the process is divided into multiple threads, if one thread completes its
execution, then its output can be immediately returned.
2. Faster context switch:
Context switch time between threads is lower compared to process context switch

3.Effective utilization of multiprocessor system:


If we have multiple threads in a single process, then we can schedule multiple
threads on multiple processor. This will make process execution faster.

4. Resource sharing:
Resources like code, data, and files can be shared among all threads within a
process.

5. Communication:
Communication between multiple threads is easier, as the threads shares common
address space. while in process we have to follow some specific communication
technique for communication between two process.

Explain user thread and kernel threads.


User-Level Threads:
In this case, the thread management kernel is not aware of the existence of
threads. The thread library contains code for creating and destroying threads, for
passing message and data between threads, for scheduling thread execution and
for saving and restoring thread contexts. The application starts with a single
thread.

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.

Kernel Threads:
 In systems that use kernel-level threads, the operating system itself is aware of
each individual thread.
 Kernel threads are supported and managed directly by the operating system.
 A context switch between kernel threads belonging to the same process requires
only the registers, program counter, and stack to be changed; the overall memory
management information does not need to be switched since both of the threads
share the same address space. Thus context switching between two kernel threads
is slightly faster than switching between two processes.
 Kernel threads can be expensive because system calls are required to switch
between threads. Also, since the operating system is responsible for scheduling the
threads, the application does not have any control over how its threads are
managed.

Advantages of Kernel-Level Threads


The kernel routines can also be multithreaded.
If a kernel-level thread is blocked, another thread of the same process can be
scheduled by the kernel.

Disadvantages of Kernel-Level Threads


A mode switch to kernel mode is required to transfer control from one thread to
another in a process.
Kernel-level threads are slower to create as well as manage as compared to user-
level threads.

Explain multithreading model in detail.//each n every 6marks


Many systems provide support for both user and kernel threads, resulting in
different multithreading models. Following are three multithreading model:

Many to One model :


 This model maps many user level threads to one kernel level thread.
 If user level thread generates blocking system call then it blocks an entire
process.
 At a time only one user level thread can access kernel level thread i.e multiple
threads can’t execute in parallel.
 Thread management is done by Thread libraries.
 Example: - Green threads – a thread library available for Solaris use many-to-
one model.

Advantages:
More concurrency.because of multiple threads can run in parallel on multiple
CPUs.
Less complication in the processing.
Disadvantages:
 One block call from kernel level thread blocks all user level threads.
 Cannot take advantage of multiprocessing.
One to One Model:
 The one to one model maps each user thread to a single kernel thread.
 It provides more concurrency than the many to one model by allowing another
thread to run when a thread makes a blocking system call.
 It also allows multiple threads to run in parallel on multiprocessors.
 Whenever user level thread is created, it compulsorily creates corresponding
kernel level thread.
 This model is used in Linux & Windows version like 95,97,XP, NT.
Advantages:
 It allows multiple threads to run in parallel on multiprocessors.
 More concurrency
 Less complication in processing
Disadvantages:
 Creating a user thread requires creating the corresponding kernel thread.
Creating kernel thread may affect the performance of an application.
 It reduces performance of the system.
 Kernel thread is overhead.
Many-to-Many Model
The many-to-many model multiplexes many user-level threads to a smaller or
equal number of kernel threads.
The number of kernel threads may be specific to either a particular application or
a particular machine (an application may be allocated more kernel threads on a
multiprocessor than on a uniprocessor).
The one-to-one model allows for greater concurrency, but the developer has to be
careful not to create too many threads within an application (and in some instances
may be limited in the number of threads she can create).
The many-to-many model suffers from neither of these shortcomings: developers
can create as many user threads as necessary, and the corresponding kernel threads
can run in parallel on a multiprocessor.
Also, when a thread performs a blocking system call, the kernel can schedule
another thread for execution.
Advantages:
Many threads can be created as per user’s requirement.
Multiple kernel or equal to user threads can be created.

Disadvantages:
True concurrency cannot be achieved.
Multiple threads of kernel is an overhead for operating system

You might also like