OS.xml
OS.xml
Program Process
1.I t isa set of instructionsthat has 1I t isan instance of a program that is
been designed to complete a cer tain being currently executed.
task.
2.I t isa passive entity. 2.I t isan active entity.
3.I t residesin the secondary 3.I t iscreated when a program isin
memory of the system. execution and isbeing loaded into the
main memory.
4.I t existsin a single place and 4.I t existsf or a limited amount of time
continuesto exist until it hasbeen and it getsterminated once the task
explicitly deleted. hasbeen completed.
5.I t isconsidered asa static entity. 5.I t isconsidered asa dynamic entity.
6.I t doesn' t have a resource 6.I t hasa high resource requirement.
requirement.
7.I t requiresmemory space to store 7.I t requiresresourcessuch asCPU,
instructions. memory address, I / Oduring itsworking.
8.I t doesn' t have a control block. 8.I t hasitsown control block, which is
known asProcessControl Block.
UNI T 3
Q1. Explain critical section problem in detail. Give necessar y condition f or
critical section problem.
- > The critical section problemisa classicsynchronization problemin computer science,
particularly in the context of concurrent or parallel programming. I t ariseswhen multiple
processesor threadsshare a common resource (such asmemory, data, or hardware device) and
must accessit in a mutually exclusive manner to avoid conf lictsand ensure data consistency.
Mutual Exclusion:
● Only one process may be executing in its critical section at a given time.
● I f process PiP_ iPi is executing in its critical section, then no other processes
can execute in their critical sections simultaneously.
Progress:
● I f no process is executing in its critical section and some processes wish to
enter their critical sections, then only those processes that are not in their
remainder sections can par ticipate in deciding which will enter next, and this
decision cannot be postponed indefinitely.
Bounded Waiting:
● There exists a bound on the number of times other processes are allowed to
enter their critical sections af ter a process has made a request to enter its
critical section and bef ore that request is granted.
● This ensures that no process can be indefinitely postponed f rom entering its
critical section
Q.2 Explain Dining philosopher problem ChatGPT
The Dining Philosophers problem is a classic synchronization problem that illustrates
the challenges of resource allocation and deadlock avoidance in concurrent
programming. I t was f ormulated by Edsger Dij kstra in 1965 to illustrate the
dif ficulty of managing resources that are shared between multiple processes.
The problem is f ramed around a group of philosophers who sit around a circular
dining table, each with a bowl of spaghetti and a f ork between each pair of
adj acent philosophers. The philosophers spend their time thinking and eating. To
eat, a philosopher needs to pick up both the f ork on their lef t and the f ork on their
right.
The challenge arises f rom the f act that the philosophers must compete f or the f orks,
which are shared resources. I f all philosophers simultaneously pick up the f ork on
their lef t, they will create a deadlock situation, as each philosopher is waiting f or
the f ork held by their neighbor.
The key obj ectives in solving the Dining Philosophers problem are:
1. Mutual Exclusion : Only one philosopher can hold a f ork at a time to avoid
conf licts and ensure that two neighboring philosophers do not attempt to pick
up the same f ork simultaneously.
2. No Deadlock: The system must avoid situations where all philosophers are
holding one f ork and waiting indefinitely f or the other, resulting in a
deadlock.
3. Starvation Avoidance: All philosophers must have an oppor tunity to eat
eventually, ensuring f airness and preventing any philosopher f rom being
stuck in a state where they cannot acquire both f orks due to the actions of
others
The Bounded Buf f er Problem, also known as the Producer- Consumer Problem, involves
a producer that generates data and a consumer that processes the data. The data is
stored in a shared buf f er with a limited capacity. The buf f er is responsible f or handling
the synchronization and communication between the producer and the consumer
processes:
The problem’s primar y challenges are to ensure that:
● The producer doesn’t over write existing data in the buf f er bef ore it’s
consumed
● The consumer doesn’t read data that has already been processed
● The buf f er manages its limited capacity ef ficiently
The problem exemplifies common synchronization and concurrency issues in real-
world applications, such as task scheduling and inter- process communication. Also,
the problem can include multiple consumers and producers, which creates
additional challenges:
UNI T 4
Q1. What is deadlock? Explain all the necessar y conditions f or deadlock.
The main memory isa combination of two main por tions- one f or the
operating system and other f or the user program. We can implement/
achieve contiguousmemory allocation by dividing the memory par titions
into fixed size par titions.
2. Non- ContiguousMemory Allocation : Non- Contiguousmemory allocation
isbasically a method on the contrary to contiguousallocation method,
allocatesthe memory space present in dif f erent locationsto the processas
per it’srequirements. Asall the available memory space isin a distributed
pattern so the f reely available memory space isalso scattered here and
there. Thistechnique of memory allocation helpsto reduce the wastage of
memory, which eventually givesrise to I nternal and external
f ragmentation.
Sr.
No. Paging Segmentation
Memor y access is
f aster in Paging. 4.Memor y access is slower
4
in Segmentation.
I nternal f ragmentation
can be caused by Paging
because some pages 5.External f ragmentation can be
5 may be underutilized. caused by Segmentation because
some memor y blocks may not be used.
7. Explain LRU (Least Recently Used) Page replacement Policy with Example.
The Least Recently Used (LRU) page replacement policy is a popular algorithm used
in vir tual memor y management to decide which page to evict f rom physical memor y
when a page f ault occurs and there is no f ree space available. The idea behind LRU
is to replace the page that has not been accessed f or the longest period of time,
assuming that pages that have not been used recently are less likely to be used in
the near f uture. Here's howLRU works, along with an example:
HowLRU Works:
1. Maintaining Page Access Histor y:
o LRU keeps track of the order in which pages are accessed by maintaining
a data structure, such as a linked list or a queue, known as the page
access histor y.
o Each time a page is accessed (read or written), it is moved to the f ront
of the page access histor y, indicating that it has been accessed most
recently.
2. Page Replacement:
o When a page f ault occurs and there is no f ree space available in
physical memor y, the operating system selects the page that is at the
end of the page access histor y (i.e., the page that has not been
accessed f or the longest period of time) f or replacement.
o The selected page is then evicted f rom physical memor y, making space
f or the newpage to be loaded f rom secondar y storage (e.g., disk) into
physical memor y.
3. Updating Page Access Histor y:
o Af ter selecting the page f or replacement, the operating system updates
the page access histor y by removing the evicted page f rom the data
structure and adding the newpage to the f ront of the page access
histor y.
o This ensures that the page that was j ust accessed is nowat the f ront of
the page access histor y, indicating that it is the most recently accessed
page.
Example
Let us say there are 3 empty memor y locations (or slots) available. I nitially, since all
slots are empty, pages 1, 2 will be allocated to the empty memor y slots and we will
get two page f aults (because neither page 1 nor page 2 was present in the memor y).
Now, page 1 is ref erenced again .