We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 36
wUSA
MUMBATUNIVERSITY STUDENTS ASSOCIATION.
QUESTION BANK SOLUTION OF OPERATING SYSTEM
S.ESEM-IV BRANCH: COMPS/AIML/DS/IOT
Explain the nec ndition for a
the processes are run.
Deadlock is an infinite process
iv) This might cause Deadlock Problem,
Necessary Condition(for Deadlock in OS
g to occur in Operating Systems. The
Processes behind the waiting process also tend to get into waiting state. Due to this
constant waiting state of processes, the condition named Deadlock is going to occur for all the
processes which are waiting state.
iv) This is all about Hold and Wait Condition in Deadlock causing condition.
2)No Pre Emption
i) Now, let us understand about the condition named No Pre Emption wi
Deadlock in the Operating Systems,ii) First, let us understand what a Pre Emption is.
iii) When a process transitions from the running state to the ready state or from the waiting state to
the ready state, Pre Emption is employed. The resources, mostly CPU cycles, are given to the
process for a set period of time before being removed; if the process still has CPU burst time left,
itis then put back in the ready queue. Until it has its subsequent opportunity to run, the process
remains in the ready queue.
iv) According to the Non Preemptive Approach, a process cannot be skipped until the process is
completed. So, the big process which is running now is going to take infinite time to complete its
Deadlock in the Operating System.
) Mutual Exclusion is the process by which on)
present in the Operating System.
iii) If this condition is going on in the Operatiny
iv) So, due to this Infinite waiting mi
Executed in the Operating Syste
4) Circular Wait.
unning, ready, blocked, new, and exit, The model works when
goes inthe
2 process has an event wait condition then the process goes to the
g and after that to the ready state. If both conditions are true, then the process goes to
running Statelafter dispatching after which the process gets released and at last It is terminated.Five State Process Model
Possible State Transitions
‘There can be various events that lead to a state transition for a process. The possible state
transitions are given below:
i) Null -> New: A new process is created for the execution of a process.
ji) New > Ready: The system will move the process from new to ready state and now it is ready for
execution, Here a system may set a limit so that multiple processes can’t occur otherwise there
may be a performance issue.
iii) Ready -> Running: The OS now selects a process for arun and t
process in a ready state for execution.
iv) Running -> Exit: The system terminates a process if the process indic«
or if it has been aborted.
v) Running -> Ready: The reason for which tI
periodically.
vi) Running -> Blocked: A process I
may be waiting for an I/O operatio
process can continue.
viii) Ready -> Exit:
may terminate a chi
vi) System calls to preserve the security of the system through its accessibility resources, which an
OS can get. This is because system calls mainly limit the direct hardware control to the OS.
Types of System Calls
There are commonly five types of system calls. These are as follows:Types of
system Calls
1. Process Control
2. File Management
3, Device Management
4, Information Maintenance
5. Communication
1.Process Control
Process control is the system
examples include creating, load, abc
Examples:
fork() > Creates a
int is a system call that is used to deal with devices. Some examples of device
de read, device, write, get device attributes, release device, etc.What de\
managementit
management does;
Examples:
+ loctl(fd, command) -> Controls a device.
= read{fd, buffer, size) -> Reads from a device.
+ write(fd, buffer, size) > Writes to a device.
+ close() -> Closes device access.4. Information Maintenance
¢ Is a system call that is used to maintain information. There are some
‘ance, including getting system data, set time or date, get time or
ual information maintenance in everyday life activities are;
Information maintenanc
‘examples of information mainten:
date, set system data, etc.. The ust
Examples:
+ getpid() > Returns process ID.
+ géttimeofday() > Gets system time.
+ uname() > Retrieves system information.
= alarm() > Sets an alarm for a process.
5. Communication
Communication is a system call that is used for commu!
Sflon connections,
ic way in which a co
xecuted on. A system Call is a way for programs to interact
rogram makes fem call when it requests the
erfices of the operating system to the user
programs via
kernel syste
‘Introduction to System Call
can interact with the operating system using a system call. A number of services
Auser pro
the 0S responds by launching a number of systems calls to
are requested by the program, and
fulfill the request.
stem call can be written In high-level languages like C or Pascal or in assembly language. If a
the operating system may directly invoke system calls, which are
= Asy
high-level language is used,
predefined functions.
Services Provided by System Calls 7
+ Process Creation and Management+ Main Memory Management
+ File Access, Directory, and File System Management
+ Device Handling(I/O)
+ Protection
+ Networking, etc,
+ Process Control: end, abort, create, terminate, allocate, and free memory.
+ File Management: create, open, close, delete, read files, etc.
+ Device Management
+ Information Maintenance
+ Communication
Features of System Calls
+ Interface: System calls provide a well-defin
operating system. Programs make request
system responds by executing the request
calling specific functions, and
rvice and returning a result.
: When the OS sees the system call then it recognizes that
this time so it temporarily stops the program execution and gives all
of itself called ‘Kernel’, Now ‘Kernel’ solves the need of the
operation|thatis requested by the program. Example: reading content from a file etc,
+ Operating system give control back to the program: After performing the special operation, OS
give control back to the program for further execution of program.[Ans: The Producer-Consumer Problem isa classic synchronization problem in Operating Systems
where two processes, Producer and Consumer, share 2 commen buffer.
‘+ The Producer adds tems tothe butfer.
+ ‘The Consumer removes items from the buffer.
+ Synchronization ie needed to prevent race condltlons and ensure proper execution.
‘Solution Using Semaphores: Semaphores are used to synchronize Producer and Consumer
processes to avoid bulfer overflow (Producer adding when fll and bdtfec underflow (Consumer
Femoving when empty)
We use three semaphores:
2) mutex (alnary Semaphore - Initially 2)
‘+ Ensures mutual exclusion, allowing only one process (Produ
the butfer at atime.
2) full (Counting Semaphore - Initially 0)
+ Keeps track of the number of filed ety in the buffer.
'3} empty (Counting Semaphore - Initially MsWhere Nis buffer size)
+ Keeps track ofthe number of ems
Algorithm for Producer:
21) Wait until there is an empty so
2) Acquire the mutex lock (waitimut
43} Produce an item and add it to the buf
[signal(mutex))
5} Increase the
vold producer) {
2) Acauire the mutex lock (walt(mutex)}.
5) Remove an item from the biffer.
4) Release the mutex (signallmutex)
5) Increase the empty count (signallempty)
void consumert}
wile (true) {
waitful// Check f buffer has tems
walt(mutex); // Lock access
‘consume. jtem|); // Remove Item from buffer5) Inerease the empty count (signallempty)
void consumer()
while (tue)
walt(ull), // Checkif buffer has items
wait{mutex); // Lock access
consume_|tem();// Remove item from buffer
signallmutex); // Unlock access
signallempty); // Increase empty slots
)
‘Working ofthe Solution:
21) Producer produces an item and adds it tothe buffer If there i
2) Consumer removes an item only ifthe buffer isnot empty,
3) Mutex ensures that oniy one process modifi
44) Synchronization is achleved using full and
jon Graph and each resource inthe yee provides only one
lock For example, if process P2 holds resource A,
there ia evel inthe Resource Allocat
instance, then the processes wil be In dead
Eee Lede senpuren WE ant soreendn FA
"Is waltng for R2 and process P2 is walting for R, then